Detailed description of the xmldocument class in Delphi (6)-access node attributes

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; button3: tbutton; Procedure submit (Sender: Taobao); Procedure submit (Sender: tobject ); procedure button3click (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; // obtain the root element attribute procedure tform1.button1click (Sender: tobject); var nodelist: ixmlnodelist; node: ixmlnode; begin showmessage (inttostr (xmldocument1.documentelement. attributenodes. count); {1} showmessage (xmldocument1.documentelement. attributes ['note']); {test} {access the attribute by attribute name. Generally, attributes ['attribute name']} showmessage (xmldocument1.documentelement. attributenodes [0]. text); {test} {access attributes through attribute locations. attributenodes [location id]} {can also be accessed through attributenodes ['attribute name'], for example :} showmessage (xmldocument1.documentelement. attributenodes ['note']. text); {test} {attributenodes is the attribute list of a node. It is also a node list object, such as:} nodelist: = xmldocument1.documentelement. attributenodes; node: = nodelist [0]; showmessage (node. text); {test} node: = nodelist ['note']; showmessage (node. text); {test} end; // access the attributes of the second person procedure tform1.button2click (Sender: tobject); var nodelist: ixmlnodelist; node: ixmlnode; begin nodelist: = xmldocument1.documentelement. childnodes; node: = nodelist [1]; showmessage (inttostr (node. attributenodes. count); {1} showmessage (node. attributes ['post']); {Deputy Chief} showmessage (node. attributenodes [0]. text); {Deputy Chief} end; // access all attributes of a node procedure tform1.button3click (Sender: tobject); var nodelist: ixmlnodelist; node: ixmlnode; num, I: integer; begin nodelist: = xmldocument1.documentelement. childnodes; node: = nodelist [0]; num: = node. attributenodes. count; for I: = 0 to num-1 do begin showmessage (node. attributenodes [I]. text); {It will display: Section Chief at the current stage} 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.