Inserting XmlNodes

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 XmlNodes 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
 XmlNodeXmlDocumentXmlAttributeXmlElementXmlTextXmlCommentXmlCDataSectionXmlProcessingInstructionXmlDeclarationXmlDocumentFragmentXmlEntityReferenceXmlWhitespaceXmlSignificantWhitespace
XmlDocument   X X XX  XX
XmlAttribute    X     X  
XmlElement   XXXXX  XXX
XmlText             
XmlComment             
XmlCDataSection             
XmlProcessingInstruction             
XmlDeclaration             
XmlDocumentFragment   XXXXX  XXX
XmlEntityReference    X        
XmlWhitespace             
XmlSignificantWhitespace             

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.93.0