Delphi operation xml document

Source: Internet
Author: User
First, Virtualize a test file: Test. xml; put it under C:/temp/for backup. </P> <p> <? XML version = "1.0" encoding = "gb2312"?> Zhang San name & gt; <br/> male gender & gt; <br/> 34 age & gt; <br/> Personnel & gt; </P> <p> Li Si name & gt; <br/> Female Gender & gt; <br/> 43 Age & gt; <br/> Personnel & gt; </P> <p> Wang Wu name & gt; <br/> Female Gender & gt; <br/> 25 age & gt; <br/> Personnel & gt; </P> <p> sun 6 name & gt; <br/> male gender & gt; <br/> 52 age & gt; <br/> Personnel & gt; </P> <p> support staff & gt; </P> <p> Department List & gt; <br/>
Unit Unit1; interfaceuses Classes, Controls, Forms, StdCtrls, XMLDoc, xmldom, XMLIntf, msxmldom; type TForm1 = class (TForm) XMLDocument1: TXMLDocument; Memo1: TMemo; Button1: TButton; button2: TButton; Button3: TButton; Button4: TButton; procedure Button1Click (Sender: TObject); procedure upload (Sender: TObject); procedure Button3Click (Sender: TObject ); procedure Button4Click (Sender: TObject); end; var Form1: TForm1; implementation {$ R *. dfm} // Loading Method 1: LoadFromFileprocedure TForm1.Button1Click (Sender: TObject); begin XMLDocument1.LoadFromFile ('C:/temp/test. xml '); Memo1.Lines: = XMLDocument1.XML; {view} end; // Load Method 2: Specify the FileName, and then activate procedure TForm1.Button2Click (Sender: TObject); begin XMLDocument1.FileName: = 'C: /temp/test. xml'; XMLDocument1.Active: = True; {activation} Memo1.Lines: = XMLDocument1.XML; {view} end; // Loading Method 3: Specify LoadFromStreamprocedure TForm1.Button3Click (Sender: TObject); var ms: TMemoryStream; begin MS: = TMemoryStream. create; ms. loadFromFile ('C:/temp/test. xml'); XMLDocument1.LoadFromStream (ms); ms. free; Memo1.Lines: = XMLDocument1.XML; {view} end; // you can use LoadFromFile or specify the FileName method to access xmlprocedure TForm1.Button4Click (Sender: TObject) on the Internet. begin XMLDocument1.LoadFromFile: // www.google.com/ig/skins/jr.xml'); Memo1.Lines: = XMLDocument1.XML; {view} end; end.
  To view XML in a browser, you need an API function: shellapi. shellExecute, so uses shellapi first; then: ShellExecute (handle, 'open', 'c:/temp/test. xml', nil, nil, sw_normal );

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.