Inserting XmlNode s


Inserting XmlNode s

It is important to remember that the XmlNode creation method creates an XmlNode only in the context of the current document. It does not, however, add the XmlNode s to the document. You must explicitly insert the nodes into the document tree. The XmlNode class provides several methods for adding nodes to the document tree.

Before we begin discussing the insertion methods, let's talk about which nodes can contain other nodes. Not all nodes are container nodes, and not all container nodes can contain every node type. For example, an XmlAttribute node is a container node that can contain only XmlText nodes. It cannot contain an XmlProcessingInstruction node. An InvalidOperationException is raised when a specified node cannot be inserted as a valid child of a container node because the specified node has the wrong type. Table 11.3 is a chart that describes which nodes are containers and which nodes they can contain. The classes down the left side of the chart are the container nodes. The classes across the top of the graph are the classes that can be contained. An "X" in the intersection of a row and a column signifies that the class on that row can contain the class in that column.

Table 11.3. Container Nodes and the Nodes They Can Contain
 

XmlNode

XmlDocument

XmlAttribute

XmlElement

XmlText

XmlComment

XmlCDataSection

XmlProcessingInstruction

XmlDeclaration

XmlDocumentFragment

XmlEntityReference

XmlWhitespace

XmlSignificantWhitespace

XmlDocument

     

X

 

X

 

X

X

   

X

X

XmlAttribute

       

X

         

X

   

XmlElement

     

X

X

X

X

X

   

X

X

X

XmlText

                         

XmlComment

                         

XmlCDataSection

                         

XmlProcessingInstruction

                         

XmlDeclaration

                         

XmlDocumentFragment

     

X

X

X

X

X

   

X

X

X

XmlEntityReference

       

X

               

XmlWhitespace

                         

XmlSignificantWhitespace

                         


Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net