Difference between revisions of "xpath"

From Lazarus wiki
Jump to navigationJump to search
(Add an example)
m (Fixed syntax highlighting)
 
Line 1: Line 1:
Just an XPath implementation. Should be fairly completed, but there hasn't been
+
{{xpath}}
further development recently.
+
 
 +
Just an XPath implementation. Should be fairly complete, but there hasn't been further development recently.
  
 
== Example ==
 
== Example ==
Line 22: Line 23:
 
</TS>
 
</TS>
 
</syntaxhighlight>
 
</syntaxhighlight>
<br />
 
  
<source>
+
<syntaxhighlight lang=pascal>
 
uses
 
uses
 
   DOM, XMLRead, XPath;
 
   DOM, XMLRead, XPath;
Line 39: Line 39:
 
   Xml.Free;
 
   Xml.Free;
 
end;   
 
end;   
</source>
+
</syntaxhighlight>
<br />
+
 
  
----
 
 
Back to [[fcl-xml]] overview.
 
Back to [[fcl-xml]] overview.
 +
  
 
[[Category:XML]]
 
[[Category:XML]]

Latest revision as of 09:22, 3 March 2020

English (en)

Just an XPath implementation. Should be fairly complete, but there hasn't been further development recently.

Example

ts.xml

<?xml version="1.0" ?><!DOCTYPE TS><TS language="es_ES" version="2.1">
<context>
    <name>AboutDialog</name>
    <message>
        <location filename="../src/lib/other/aboutdialog.ui" line="60"/>
        <source>Authors</source>
        <translation>Autores</translation>
    </message>
    <message>
        <location filename="../src/lib/other/aboutdialog.cpp" line="56"/>
        <source>Authors and Contributors</source>
        <translation>Autores y contribuidores</translation>
    </message>
</context>
</TS>
uses
  DOM, XMLRead, XPath;

var
  Xml: TXMLDocument;
  XPathResult: TXPathVariable;
begin
  ReadXMLFile(Xml, 'ts.xml');
  //Get text inside <translation> tag
  XPathResult := EvaluateXPathExpression('/TS/context[name="AboutDialog"]/message[source="Authors"]/translation', Xml.DocumentElement);
  ShowMessage(String(XPathResult.AsText));
  XPathResult.Free;
  Xml.Free;
end;


Back to fcl-xml overview.