Sign in Join
Wiki copytemporary

xpath: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: xpath

OldNewLine
1+Just an XPath implementation. Should be fairly complete, but there hasn't been further development recently.
2+
3+## Example
4+
5+**ts.xml**
6+
7+``` xml
8+<?xml version="1.0" ?><!DOCTYPE TS><TS language="es_ES" version="2.1">
9+<context>
10+ <name>AboutDialog</name>
11+ <message>
12+ <location filename="../src/lib/other/aboutdialog.ui" line="60"/>
13+ <source>Authors</source>
14+ <translation>Autores</translation>
15+ </message>
16+ <message>
17+ <location filename="../src/lib/other/aboutdialog.cpp" line="56"/>
18+ <source>Authors and Contributors</source>
19+ <translation>Autores y contribuidores</translation>
20+ </message>
21+</context>
22+</TS>
23+```
24+
25+``` pascal
26+uses
27+ DOM, XMLRead, XPath;
28+
29+var
30+ Xml: TXMLDocument;
31+ XPathResult: TXPathVariable;
32+begin
33+ ReadXMLFile(Xml, 'ts.xml');
34+ //Get text inside <translation> tag
35+ XPathResult := EvaluateXPathExpression('/TS/context[name="AboutDialog"]/message[source="Authors"]/translation', Xml.DocumentElement);
36+ ShowMessage(String(XPathResult.AsText));
37+ XPathResult.Free;
38+ Xml.Free;
39+end;
40+```
41+
42+Back to [[fcl-xml]] overview.
43+
44+---
45+*From the Free Pascal wiki, page "xpath", as it stood on 2020-03-03 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
46+Category: XML

Back to history