XML node types

admin's picture

 
XML document can be shown as a tree.
The tree contains nodes. There are seven types of node:

  • root nodes
  • element nodes
  • text nodes
  • attribute nodes
  • namespace nodes
  • processing instruction nodes
  • comment nodes

For every type of node, there is a way of determining a string-value for a node of that type. For some types of node, the string-value is part of the node; for other types of node, the string-value is computed from the string-value of descendant nodes.

Root node

Each XML has exactly one single root element. This element is also known as the document element.
It is always the very first element in XML tree, just can be preceded by prolog line. See the example:
 
<?xml version="1.0" encoding="UTF-8"?>
<rootElement>
     <AAA/>
     <BBB/>
</rootElement>

 The root node is the root of the tree. A root node does not occur except as the root of the tree. The element node for the document processing instructions and comments that occur in the prolog and after the end of the document element.
The root node does not have an expanded-name.
Expanded name - Some types of node also have an expanded-name, which is a pair consisting of a local part and a namespace URI. The local part is a string. The namespace URI is either null or a string. The namespace URI specified in the XML document can be a URI reference, this means it can have a fragment identifier and can be relative. A relative URI should be resolved into an absolute URI during namespace processing: the namespace URIs of expanded-names of nodes in the data model should be absolute. Two expanded-names are equal if they have the same local part, and either both have a null namespace URI or both have non-null namespace URIs that are equal.

Element Nodes

The Element object represents an element in an XML document. Elements may contain attributes, other elements, or text. If an element contains text, the text is represented in a text-node.
<element attribute-name = "attribute-value">....</element>
 
 <element>
   <childElement>...   </childElement>
</element>
 
<element>anyText</element>
There is an element node for every element in the document. An element node has an expanded-name computed by expanding the QName of the element specified in the tag in accordance with the XML Namespaces Recommendation. The namespace URI of the element's expanded-name will be null if the /public_html/cgi-bin has no prefix and there is no applicable default namespace.

Text Nodes

Character data is grouped into text nodes. As much character data as possible is grouped into each text node: a text node never has an immediately following or preceding sibling that is a text node. The string-value of a text node is the character data. A text node always has at least one character of data.

Attribute Nodes

Each element node has an associated set of attribute nodes; the element is the parent of each of these attribute nodes; however, an attribute node is not a child of its parent element.
 <element attribute-name = "attribute-value">....</element>

 Namespace Nodes

Each element has an associated set of namespace nodes, one for each distinct namespace prefix that is in scope for the element (including the xml prefix, which is implicitly declared by the XML Namespaces Recommendation and one for the default namespace if one is in scope for the element. The element is the parent of each of these namespace nodes; however, a namespace node is not a child of its parent element. Elements never share namespace nodes: if one element node is not the same node as another element node, then none of the namespace nodes of the one element node will be the same node as the namespace nodes of another element node.
 <?xml version="1.0" encoding="UTF-8"?>
<html      
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xf="http://www.w3.org/2002/01/xforms"
      xmlns:xlink="http://www.w3.org/1999/xlink"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:scixf="http://www.sterlingcommerce.com/xforms/xforms-extensions" xmlns:r="http://www.sterlingcommerce.com/xforms/request">
      <head>     
            <xf:model id="model">
                  <xf:instance xlink:href="/webx/bp/BKT_testRunBP"></xf:instance>
<xf:bind id="ime" ref="/tempXML/IME" isValid="string-length(.) &gt; 4 " scixf:reason="Upozorenje: String ime mora biti duzi od 4 znaka!"/>
 
            </xf:model>
</head>
      <body>
            <xf:group id="xform-body">
            <xf:caption>Upisite ime: </xf:caption>
                  <xf:input ref="tempXML/IME">
                        <xf:caption>Upisite ime: </xf:caption>
                        <xf:hint>Ovdje morate upisati ime!</xf:hint>
                  </xf:input>
                  <br/>
                  ...
</html> 

Processing Instruction Nodes

There is a processing instruction node for every processing instruction, except for any processing instruction that occurs within the document type declaration. The XML declaration is not a processing instruction. Therefore, there is no processing instruction node corresponding to the XML declaration.
Processing Instructions are information for the application. PI's allow documents to contain instructions for applications. They are not really of interest to the XML parser. Instead, the instructions are passed to the application using the parser, because the purpose of processing instructions is to represent special instructions for the application.
 
<?name pidata?>
 <?xml version="1.0"? encoding="UTF-8" standalone="yes"?>

 Comment Nodes

A comment is used to leave a note or to temporarily edit out a portion of XML code. Although XML is supposed to be self-describing data, you may still come across some instances where an XML comment might be necessary.
The syntax for writing comments in XML is similar to that of HTML.
<!-- This is a comment -->
 
A comment node does not have an expanded-name