PrevNextUpHome SophiaFramework UNIVERSE 5.3

19.2. Structure of XML Classes

19.2.1. Classes for Creating Nodes for the DOM Tree

SophiaFramework provides you with the following 12 types of node classes defined by W3C. These classes inherit from the SFXXMLNode class.

Table 19.1. XML Node Class

Class name Description Node Type ( SFXXMLNode::NodeType )
SFXXMLNode Base class for 12 types of node classes. -
SFXXMLElement Class which represents an Element node. ELEMENT_NODE
SFXXMLAttribute Class which represents an Attribute node. ATTRIBUTE_NODE
SFXXMLText Class which represents a Text node. TEXT_NODE
SFXXMLCDATASection Class which represents a CDATASection node. CDATA_SECTION_NODE
SFXXMLEntityReference Class which represents an Entity Reference node. ENTITY_REFERENCE_NODE
SFXXMLEntity Class which represents an Entity node. ENTITY_NODE
SFXXMLProcessingInstruction Class which represents a Processing Instruction node. PROCESSING_INSTRUCTION_NODE
SFXXMLComment Class which represents a Comment node. COMMENT_NODE
SFXXMLDocument Class which represents a Document node. DOCUMENT_NODE
SFXXMLDocumentType Class which represents a DocumentType node. DOCUMENT_TYPE_NODE
SFXXMLDocumentFragment Class which represents a DocumentFragment node. DOCUMENT_FRAGMENT_NODE
SFXXMLNotation Class which represents a Notation node. NOTATION_NODE

Figure 19.1. DOM Tree of the SFXXMLNode nodes

DOM Tree of the SFXXMLNode nodes

19.2.2. Basic Function of SFXXMLNode

The following are provided as basic functions of the SFXXMLNode class.

Table 19.2. Function to get a node from the DOM tree

Function Name Description
GetFirstChild Get the first child node.
GetLastChild Get the last child node.
GetNextSibling Get the next node amongst brothers.
GetPreviousSibling Get the previous node amongst brothers.
GetParentNode Get the parent node.

Table 19.3. Function to create or update the DOM tree

Function Name Description
AppendChild Append the specified child node.
RemoveChild Remove the specified child node.
ReplaceChild Replace the specified child node.
InsertBefore Insert the specified node.
CloneNode Clone the specified node(It is possible to copy the specified node including child node trees).

Table 19.4. Function to get or set the node attribute

Function Name Description
HasChildNodes Check whether or not the node has any child nodes.
GetChildNodes Get all child nodes.
GetNodeType Get the node type.
GetNodeName Get the node name.
SetNodeValue Set the node value.
GetText Get the text from the node value.
SetText Set the specified text into the node value.

Table 19.5. Function to compare nodes

Function Name Description
IsSameNode Check whether or not the node is the same with the specified node.
EqualNode Check whether or not the node equals the specified node.

19.2.3. Structure of the DOM Tree

An XML parser receives XML documents grammatically checked by DTD or XML Schema, expands the documents onto memory as tree-structured objects ( DOM tree ), and sends them to an application.

Figure 19.2. Process Flow on XML parser

Process Flow on XML parser

In SophiaFramework, a DOM parser (SFXXMLDOMParser) is created to analyze XML document, and return an DOM tree of SFXXMLDocument.

Figure 19.3. Sequence Diagram

Sequence Diagram
[Note] SFXXMLScanner

SFXXMLScanner is the class used by SophiaFramework.

Figure 19.4. SFXXMLDocument

SFXXMLDocument

The most important object in parsing XML document is the root node of SFXXMLDocument in the DOM tree.

Basic Functions of "SFXXMLDocument"

  1. Create, update, compare, and get nodes.
  2. Construct the DOM tree with nodes.
  3. Save the DOM tree as the XML document.
  4. Get any node in the DOM tree with the Helper function.