Lazarus Reading xml-with txmldocument and Txpathvariable

Source: Internet
Author: User

That is, the use of XPath, the specific syntax rules to see http://www.w3school.com.cn/xpath/xpath_syntax.asp, the explanation is quite detailed. Examples are given here to illustrate the specific application of the LAZARUS/FPC, as well as considerations. First, you can construct a "readxpath" function for easy invocation. After all, there are some tasks to be dealt with after each use of evaluatexpathexpression ....

View Plaincopy to Clipboardprint
  1. function Readxpath (const anode:tdomnode; Const Apath: string   ): Tdomnode;
  2. var   
  3. rv:txpathvariable;
  4. Tl:tfplist;
  5. begin   
  6. Result: = Nil   ;
  7. if Assigned (anode) Then
  8. begin
  9. RV: = Evaluatexpathexpression (Apath, anode);
  10. if Assigned (RV) Then
  11. begin
  12. tl: = RV .   Asnodeset;
  13. if Assigned (TL) Then
  14. begin
  15. if tl. Count > 0 then
  16. begin
  17. Result: = Tdomnode (tl[0]);
  18. end;
  19. end;
  20. end;
  21. end;
  22. End   ;

Specifically used, to remember that the return is actually "element", even if the mandatory Convention "property"--[@Attrib], so to read any value, you have to press "scan to Element" way to handle.

View Plaincopy to Clipboardprint
  1. function readcfg: Boolean   ;
  2. var   
  3. .....
  4. Vconfigxml: string  =  "'   ;
  5. Historypath: string  =  "'   ;
  6. Tracepath: string  =  "'   ;
  7. Vxp:tdomnode;
  8. .....
  9. begin   
  10. Result: = False;
  11. Readxmlfile (XMLCFG, vconfigxml);
  12. VXP: = Readxpath (XMLCFG, '/config/historypath[@value] ');
  13. if Assigned (vXP) Then
  14. begin
  15. if vXP. HasAttributes Then   
  16. Historypath: = VXP . Attributes . item[0].   NodeValue;
  17. end;
  18. VXP: = Readxpath (XMLCFG, '/config/tracepath[@value] ');
  19. if Assigned (vXP) Then
  20. begin
  21. if vXP. HasAttributes Then   
  22. Tracepath: = VXP . Attributes . item[0].   NodeValue;
  23. end;
  24. if (historypath <> ") and (Tracepath <> c7> ") Then
  25. .....
  26. End       ;

Lazarus Reading xml-with txmldocument and Txpathvariable

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.