Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

XmlNodeType Enumeration

Specifies the type of node.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public enum XmlNodeType
Member nameDescription
Supported by Silverlight for Windows PhoneSupported by Xbox 360NoneThis is returned by the XmlReader if a Read method has not been called.
Supported by Silverlight for Windows PhoneSupported by Xbox 360ElementAn element (for example, <item>).

An Element node can have the following child node types: Element, Text, Comment, ProcessingInstruction, CDATA, and EntityReference. It can be the child of the Document, DocumentFragment, EntityReference, and Element nodes.

Supported by Silverlight for Windows PhoneSupported by Xbox 360AttributeAn attribute (for example, id='123').

An Attribute node can have the following child node types: Text and EntityReference. The Attribute node does not appear as the child node of any other node type. It is not considered a child node of an Element.

Supported by Silverlight for Windows PhoneSupported by Xbox 360TextThe text content of a node.

A Text node cannot have any child nodes. It can appear as the child node of the Attribute, DocumentFragment, Element, and EntityReference nodes.

Supported by Silverlight for Windows PhoneSupported by Xbox 360CDATAA CDATA section (for example, <![CDATA[my escaped text]]>).

CDATA sections are used to escape blocks of text that would otherwise be recognized as markup. A CDATA node cannot have any child nodes. It can appear as the child of the DocumentFragment, EntityReference, and Element nodes.

Supported by Silverlight for Windows PhoneSupported by Xbox 360EntityReferenceA reference to an entity (for example, &num;).

An EntityReference node can have the following child node types: Element, ProcessingInstruction, Comment, Text, CDATA, and EntityReference. It can appear as the child of the Attribute, DocumentFragment, Element, and EntityReference nodes.

Supported by Silverlight for Windows PhoneSupported by Xbox 360EntityAn entity declaration (for example, <!ENTITY...>).

An Entity node can have child nodes that represent the expanded entity (for example, Text and EntityReference nodes). It can appear as the child of the DocumentType node.

Supported by Silverlight for Windows PhoneSupported by Xbox 360ProcessingInstructionA processing instruction (for example, <?pi test?>).

A ProcessingInstruction node cannot have any child nodes. It can appear as the child of the Document, DocumentFragment, Element, and EntityReference nodes.

Supported by Silverlight for Windows PhoneSupported by Xbox 360CommentA comment (for example, <!-- my comment -->).

A Comment node cannot have any child nodes. It can appear as the child of the Document, DocumentFragment, Element, and EntityReference nodes.

Supported by Silverlight for Windows PhoneSupported by Xbox 360DocumentA document object that, as the root of the document tree, provides access to the whole XML document.

A Document node can have the following child node types: XmlDeclaration, Element (maximum of one), ProcessingInstruction, Comment, and DocumentType. It cannot appear as the child of any node types.

Supported by Silverlight for Windows PhoneSupported by Xbox 360DocumentTypeThe document type declaration, indicated by the following tag (for example, <!DOCTYPE...>).

A DocumentType node can have the following child node types: Notation and Entity. It can appear as the child of the Document node.

Supported by Silverlight for Windows PhoneSupported by Xbox 360DocumentFragmentA document fragment.

The DocumentFragment node associates a node or subtree with a document without actually being contained in the document. A DocumentFragment node can have the following child node types: Element, ProcessingInstruction, Comment, Text, CDATA, and EntityReference. It cannot appear as the child of any node types.

Supported by Silverlight for Windows PhoneSupported by Xbox 360NotationA notation in the document type declaration (for example, <!NOTATION...>).

A Notation node cannot have any child nodes. It can appear as the child of the DocumentType node.

Supported by Silverlight for Windows PhoneSupported by Xbox 360WhitespaceWhite space between markup.
Supported by Silverlight for Windows PhoneSupported by Xbox 360SignificantWhitespaceWhite space between markup in a mixed content model or white space within the xml:space="preserve" scope.
Supported by Silverlight for Windows PhoneSupported by Xbox 360EndElementAn end element tag (for example, </item>).

EndElement nodes are returned when XmlReader reaches the end of an element.

Supported by Silverlight for Windows PhoneSupported by Xbox 360EndEntityReturned when XmlReader reaches the end of the entity replacement as a result of a call to ResolveEntity.
Supported by Silverlight for Windows PhoneSupported by Xbox 360XmlDeclarationThe XML declaration (for example, <?xml version='1.0'?>).

The XmlDeclaration node must be the first node in the document. It cannot have children. It is a child of the Document node. It can have attributes that provide version and encoding information.

The following example navigates through the stream to determine the current node type, and then uses XmlWriter to output the XmlReader content.


StringBuilder output = new StringBuilder();

String xmlString =
        @"<?xml version='1.0'?>
        <!-- This is a sample XML document -->
        <Items>
          <Item>test with a child element <more/> stuff</Item>
        </Items>";
// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
    XmlWriterSettings ws = new XmlWriterSettings();
    ws.Indent = true;
    using (XmlWriter writer = XmlWriter.Create(output, ws))
    {

        // Parse the file and display each of the nodes.
        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    writer.WriteStartElement(reader.Name);
                    break;
                case XmlNodeType.Text:
                    writer.WriteString(reader.Value);
                    break;
                case XmlNodeType.XmlDeclaration:
                case XmlNodeType.ProcessingInstruction:
                    writer.WriteProcessingInstruction(reader.Name, reader.Value);
                    break;
                case XmlNodeType.Comment:
                    writer.WriteComment(reader.Value);
                    break;
                case XmlNodeType.EndElement:
                    writer.WriteFullEndElement();
                    break;
            }
        }

    }
}
OutputTextBlock.Text = output.ToString();


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.