Nevron Open Vision Documentation
XML Document Object Model

The XML Document Object Model is an in-memory tree representation of an XML document and allows for easy navigation and manipulation of this document. The XML DOM provided by Nevron Open Vision is built around the NXmlDocument, NXmlNode and NXmlElement classes. The following diagram illustrates the class hierarchy of the Nevron XML DOM:

The sections below describe the functionality these classes provide in more details.

Xml Nodes

NXmlNode is the base abstract class, which all XML DOM objects inherit. Any XML node has a name, a type, a reference to its parent XML node, a list of children and a list of declarations. Nevron Open Vision supports the following types of XML nodes:

XML Node Type Description
Document Represents a XML document.
Element Represents a XML element. XML elements are XML nodes, which can have attributes.
Declaration Represents a XML declaration, for example - <?xml version="1.0" encoding="UTF-8"?>
Text Represents a XML text node, which contains the text content of a XML element.
Comment Represents a XML comment, i.e. a XML text node surrounded by "<!--" and "-->".
CDATA Represents a XML data section, i.e. a XML text node surrounded by "<![CDATA[" and "]]>".

The list below describes how to perform the most common actions on XML nodes:

Xml Text Nodes 

XML text nodes are XML nodes that contain text data. They are usually leaf nodes in the DOM tree (i.e. they do not have any child nodes) and the only properties of interest for them are the Text property, which contains the text data of the node and the NodeType property, which indicates the type of the node. XML text nodes can be of type Text, Comment and CDATA.

Xml Elements

XML elements are XML nodes, which can have attributes. To determine how many attributes an XML element has, use the AttributeCount property. Through the SetAttribute method you can add/update an attribute name/value pair to the XML element. The RemoveAttribute method removes an attribute from the element and the ClearAttributes method removes all attributes from it. If you want to get the value of an attribute with a given name, simply call the GetAttribute method.

The GetAttribute method returns null if the XML element does not contain an attribute with the given name.

To loop through the attributes of an XML element, you should use the GetAttributesIterator method to obtain an attributes iterator:

Iteration over XML element's attributes
Copy Code
INIterator<NKeyValuePair<string, string>> iter = xmlElement.GetAttributesIterator();
while (iter.MoveNext())
    string attributeName = iter.Current.Key;
    string attributeValue = iter.Current.Value;

    // Process the attribute here
Xml Document 

The NXmlDocument is a XML node that is usually the root node of every XML DOM tree. You can navigate and manipulate its children in the same way you do for XML nodes. The NXmlDocument class extends the NXmlNode class with the ability to load and save XML documents from and to a stream:

See Also
Send Feedback