Tài liệu Using an XmlDocument Object to Store an XML Document doc - Pdf 87


Using an XmlDocument Object to Store an XML Document
You use an object of the XmlDocument class to represent an XML document in a C#
program. An XmlDocument object stores the nodes of the XML document in objects of
the XmlNode class. You can, for example, load rows from the database into a DataSet
object, and then load an XML representation of those rows into an XmlDocument object.
Table 16.5
shows some of the XmlDocument properties; Table 16.6 shows some of the
XmlDocument methods; and Table 16.7
shows the XmlDocument events.
Table 16.5: XmlDocument Properties
Property Type Description
Attributes XmlAttributeCollection Gets the XmlAttributeCollection object
that contains the attributes of the current
node.
BaseURI string Gets the base URI of the current node.
ChildNodes XmlNodeList Gets all the child nodes of the node.
DocumentElement XmlElement Gets the root XmlElement object for the
XML document.
DocumentType XmlDocumentType Gets the node containing the DOCTYPE
declaration.
FirstChild XmlNode Gets the first child of the node.
HasChildNodes bool Gets a bool that indicates whether this node
has any child nodes.
Implementation XmlImplementation Gets the XmlImplementation object for the
XML document.
InnerText string Gets or sets the concatenated values of the
node and all of its children.
InnerXml string Gets or sets the XML that represents the
children of the current node.
IsReadOnly bool Gets a bool value that indicates whether the

AppendChild() XmlNode Adds the specified node to the end
of child nodes.
CloneNode() XmlNode Creates a duplicate of the node.
CreateAttribute() XmlAttribute Creates an XmlAttribute object of
the specified name.
CreateCDataSection() XmlCDataSection Creates an XmlCDataSection
object with the specified data.
CreateComment() XmlComment Creates an XmlComment object
with the specified data.
CreateDocumentFragment() XmlDocumentFragment Creates an
XmlDocumentFragment object
with the specified data.
Table 16.6: XmlDocument Methods
Method Return Type Description
CreateDocumentType() XmlDocumentType Creates a new XmlDocumentType
object with the specified data.
CreateElement() XmlElement Overloaded. Creates an
XmlElement object.
CreateEntityReference() XmlEntityReference Creates an XmlEntityReference
object with the specified name.
CreateNavigator() XpathNavigator Creates an XpathNavigator object
that you can use to navigate the
XML document.
CreateNode() XmlNode Overloaded. Creates an XmlNode
object.
CreateTextNode() XmlText Creates an XmlText object with
the specified text.
CreateWhitespace() XmlWhitespace Creates an XmlWhitespace object.
CreateXmlDeclaration() XmlDeclaration Creates an XmlDeclaration object.
GetElementById() XmlElement Gets the XmlElement object with

XmlDocument object.
PrependChild() XmlNode Adds the specified node to the
beginning of the child nodes.
ReadNode() XmlNode Creates an XmlNode object based
on the information in a specified
XmlReader object. Your
XmlReader must be positioned on
a node or attribute.
RemoveAll() void Removes all the children and
attributes of the current node.
RemoveChild() XmlNode Removes the specified child node.
ReplaceChild() XmlNode Replaces one child node with
another.
Save() void Overloaded. Saves the XML
document to the specified location.
SelectNodes() XmlNodeList Overloaded. Selects a list of nodes
matching the specified XPath
expression.
SelectSingleNode() XmlNode Overloaded. Selects the first
XmlNode that matches the
specified XPath expression.
WriteContentTo() void Saves all the children of the XML
document to the specified
XmlWriter object.
WriteTo() void Saves the XML document to the
specified XmlWriter object.
Table 16.7: XmlDocument Events
Event Event Handler Description
NodeChanging XmlNodeChangedEventHandler Fires before a value in a node is
changed.

*/

using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status