Difference between revisions of "xpath"

From Lazarus wiki
Jump to navigationJump to search
(New page: Just a XPath implementation. Should be fairly completed, but there hasn't been further development recently. Back to fcl-xml overview.)
 
m (Fixed syntax highlighting)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Just a 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 ==
 +
 
 +
'''ts.xml'''
 +
<syntaxhighlight lang="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>
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang=pascal>
 +
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; 
 +
</syntaxhighlight>
 +
 
  
 
Back to [[fcl-xml]] overview.
 
Back to [[fcl-xml]] overview.
 +
 +
 +
[[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.