Detailed description of the xmldocument class in Delphi (13)-about XML attributes

Source: Internet
Author: User
Tags xml attribute
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, xmldom, xmlintf, msxmldom, xmldoc, stdctrls; Type tform1 = Class (tform) xmldocument1: txmldocument; memo1: tmemo; button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; button5: tbutton; Procedure upload (Sender: tobject ); procedure button1click (Sender: tobject); Procedure Button2click (Sender: tobject); Procedure button3click (Sender: tobject); Procedure button4click (Sender: tobject); Procedure destroy (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} // open procedure tform1.formcreate (Sender: tobject); begin xmldocument1.loadfromfile ('C: \ temp \ test. XML '); {you must use the XML test file provided in case to have the same return value} end; // XML Attribute procedure tform1.button1click (Sender: Tobject); begin {we often use this sentence before, because the lines and XML here belong to tstrings} memo1.lines: = xmldocument1.xml; {if you are not afraid of trouble, you can also write it like this :} memo1.lines. text: = xmldocument1.xml. text; {if you know this, there will be more functions of the XML attribute, and the XML Attribute here is writable} {but here we will talk about the XML Attribute of the node} end; // The XML Attribute procedure tform1.button2click (Sender: tobject) of the root node; var node: ixmlnode; begin {first view the root node: xmldocument1.documentelement} node: = xmldocument1.documentelement; // memo1.lines: = Node. XML; {this sentence will cause an error} {because the XML Attribute of the node is of the widestring type, it should be like this:} memo1.lines. text: = node. XML; {all content contained in the root node and the root node will be read.} {There is another bigger difference: the XML of the node is read-only !} End; // The XML Attribute procedure tform1.button3click (Sender: tobject) of the subnode; var node: ixmlnode; begin node: = xmldocument1.documentelement; node: = node. childnodes [0]; memo1.lines. text: = node. XML; {displays all of the Child Nodes} end; // The XML Attribute procedure tform1.button4click (Sender: tobject); var node: ixmlnode; begin node: = xmldocument1.documentelement; node: = node. attributenodes [0]; {the property is also of the ixmlnode type} showmessage (node. nodename); {remarks} showmessage (node. nodevalue); {test} {read them all once using XML attributes:} showmessage (node. XML); {remarks = "test"} end; // The XML Attribute procedure tform1.button5click (Sender: tobject) of the leaf node; var node: ixmlnode; begin node: = xmldocument1.documentelement; node: = node. childnodes [0]; node: = node. childnodes [0]; node: = node. childnodes [0]; {This is the leaf node} showmessage (node. XML); {zhangsan} {the XML Attribute is the same as the text attribute} showmessage (node. text); {zhangsan} 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.