Once an XML document has been parsed by a DOM implementation, the data it represents is available as a hierarchy of nodes Each node corresponds to a tagged element in the document For example, given the following XML..:
Component Palette XML Version = "1.0" Standalone = 'YES'?>
TXMLDocument would generate a hierarchy of nodes as follows: The root of the hierarchy would be the StockList node StockList would have two child nodes, which correspond to the two Stock tags Each of these two child nodes would have four child nodes of its own.. (Name, Price, Symbol, And Sharees). Those Four Child Nodes Would Not As Leaf Nodes. The text The Contain Wouldes. The value of each of the leaf nodes.
Note:.. This division into nodes differs slightly from the way a DOM implementation generates nodes for an XML document In particular, a DOM parser treats all tagged elements as internal nodes Additional nodes (of type text node) would be created for the values of ................... ..
Each Node Is Accessed Through An IXMLNode Interface, Starting with The Root Node, Which Is The Value of The XML Document Component 抯 DocumentElement Property.working with a node 抯 Value
Given an ixmlnode interface, you can check WHETER IT REPRESENTS An Internal Node OR A Leaf Node by Checking The IStextElement Property.
If IT Repesents a leaf node, you can read or set item node, you can access it, child node, you can aff..
Thus, for example, using the xml document Above, you can read the price of inprise 抯 Stock as Follows:
Inprisestock: = xmldocument1.documentelement.childNodes [0];
Price: = inprisestock.childnodes ['price']. Text;
Working with a node 抯 Attributes
If the node includes any attributes, you can work with them using the Attributes property You can read or change an attribute value by specifying an existing attribute name You can add new attributes by specifying a new attribute name when you set the Attributes property..:
Inprisestock: = xmldocument1.documentelement.childNodes [0];
InprisStock.childNodes ['Sharees']. Attributes ['Type']: = 'Common';
Adding and Deleting Child Nodes
You can add child nodes using the AddChild method. AddChild creates new nodes that correspond to tagged elements in the XML document. Such nodes are called element nodes.To create a new element node, specify the name that appears in the new tag and, optionally , the stock, for example, the stock listing to the document Above:
VAR
NewStock: IXMLNode; ValueNode: IXMLNode; begin NewStock: = XMLDocument1.DocumentElement.AddChild ( 'stock'); NewStock.Attributes [ 'exchange']: = 'NASDAQ'; ValueNode: = NewStock.AddChild ( 'name'); ValueNode .Text: = 'Cisco Systems' ValueNode: = NewStock.AddChild (' price '); ValueNode.Text: = '62 .375'; ValueNode: = NewStock.AddChild ( 'symbol'); ValueNode.Text: = 'CSCO'; ValueNode: = NewStock.AddChild ( 'shares'); ValueNode.Text: = '25'; end; An overloaded version of AddChild lets you specify the namespace in which the tag name is defined.You can delete child nodes using the methods of the ChildNodes property. ChildNodes is an IXMLNodeList interface, which manages the children of a node. You can use its ~ JMP Delete ~! Alink (ixmlnodelist_delete, 1, TopicNotFound, main) JMP ~> method to delete a single child node that is identified By position or by name. for example, the stock list deletes the last stock listed in The Document Above:
StockList: = xmldocument1.documentelement;
StockList.childNodes.delete (stocklist.childnodes.count - 1);