Detailed description of the xmldocument class in Delphi (9)-about haschildnodes and istextelement

Source: Internet
Author: User
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, xmldom, xmlintf, msxmldom, xmldoc, stdctrls; Type tform1 = Class (tform) xmldocument1: txmldocument; button1: tbutton; button2: tbutton; Procedure upload (Sender: tobject); Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject ); private {private Declarations} public {public declarations} end; var form1: tform1; implementation {$ R *. DFM} // open procedure tform1.formcreate (Sender: tobject); begin xmldocument1.loadfromfile ('C: \ temp \ test. XML '); {the same return value can be obtained only when an XML test file is provided.} end; // haschildnodes: determines whether the child node procedure tform1.button1click (Sender: tobject) is included ); vaR node: ixmlnode; B: Boolean; begin {we take a node from the example, such as the first node under the root node: <personnel position = "section chief" Remarks = "bureau level">
<Name> Zhang San </Name>
<Gender> male </gender>
<Age> 34 </age>
</Personnel >}{ obtain the node with the Node object} node: = xmldocument1.documentelement. childnodes [0]; {of course, this node contains sub-nodes and contains three sub-nodes} B: = node. haschildnodes; showmessage (booltostr (B); {-1; that is, true} showmessage (inttostr (node. childnodes. count); {3} showmessage (node. nodename); {personnel} {Look at the "name" node: <Name> JOHN </Name>
} {Get this node with the Node object} node: = xmldocument1.documentelement. childnodes [0]. childnodes [0]; B: = node. haschildnodes; showmessage (booltostr (B); {-1; that is, true} showmessage (inttostr (node. childnodes. count); {1} showmessage (node. nodename); {name} {it only contains the text "Zhang San", there is no label, then the node has the text attribute} showmessage (node. text); {Zhang San} {get the text node "Zhang San"} node: = xmldocument1.documentelement. childnodes [0]. childnodes [0]. childnodes [0]; B: = node. haschildnodes; showmessage (booltostr (B); {0; that is, false no subnode} showmessage (inttostr (node. childnodes. count); {0; Total number of subnodes is 0} showmessage (node. nodename); {# text; indicates that it is a text node} showmessage (node. nodevalue); {Zhang San; we can also retrieve its value} {the nodevalue attribute of the text node is equivalent to the text attribute of the upper node} showmessage (node. parentnode. text); {zhangsan} end; // istextelement: determines whether the procedure tform1.button2click (Sender: tobject); var node: ixmlnode; B: Boolean; begin {Let's take out a node from the example, for example, the first node under the root node: <personnel position = "section chief" Remarks = "bureau level">
<Name> Zhang San </Name>
<Gender> male </gender>
<Age> 34 </age>
</Personnel >}{ obtain the node with the Node object} node: = xmldocument1.documentelement. childnodes [0]; {this node certainly has no text attribute} B: = node. istextelement; showmessage (booltostr (B); {0; that is, false} showmessage (node. nodename); {personnel} {"name" Node} node: = xmldocument1.documentelement. childnodes [0]. childnodes [0]; {"name" node has the text attribute} B: = node. istextelement; showmessage (booltostr (B); {-1; that is, true} showmessage (node. nodename); {name} {"zhangsan" text node} node: = xmldocument1.documentelement. childnodes [0]. childnodes [0]. childnodes [0]; {the text node does not have the text attribute} B: = node. istextelement; showmessage (booltostr (B); {0; that is, false} showmessage (node. nodename); {# text} end; end.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.