1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
18 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
19 xmlns:scilab="http://www.scilab.org" xml:id="xmlXPath" xml:lang="en">
21 <refname>xmlXPath</refname>
22 <refpurpose>Make a XPath query on a XML document</refpurpose>
27 result = xmlXPath(xmlObj, queryStr)
28 result = xmlXPath(xmlObj, queryStr, namespaces)
32 <title>Arguments</title>
37 <para>a XML mlist typed XMLDoc or XMLElem</para>
43 <para>a Xpath query</para>
47 <term>namespaces</term>
49 <para>An optional matrix nx2 of strings</para>
55 <para>result can be a set of XMLElements or a number or a string or a boolean</para>
61 <title>Description</title>
63 Make a XPath query on a document or in starting on an element. If you need to use
64 namespaces, then you must define them in using the optional argument. XML namespaces are
65 defined in the first tag with the keyword "xmlns".
68 For more information about XPath, you can read the
69 <ulink url="http://www.w3.org/TR/1999/REC-xpath-19991116/">W3C recommandation</ulink>.
73 <title>Examples</title>
74 <programlisting role="example"><![CDATA[
75 doc = xmlRead("http://www.w3.org/TR/2009/REC-xml-names-20091208/xml-names-10-3e.xml");
77 // Retrieve the nodes with name equal to "note"
78 xp = xmlXPath(doc, "//note");
84 // Count the nodes with name equal to "note"
85 xp = xmlXPath(doc, "count(//note)")
87 // Retrieve the node with id="Philosophy"
88 xp = xmlXPath(doc, "//*[@id=""Philosophy""]");
94 // Retrieve the nodes with an attribute num equal to the number 5
95 xp = xmlXPath(doc, "//*[number(@num)=5]");
101 // Get the name and the content of all the attributes of nodes named 'emph'
102 xp = xmlXPath(doc, "//emph/@*");
108 // Query using namespaces
109 t = "<root xmlns:scilab=""http://www.scilab.org"">"+..
110 "<scilab:a att=""foo"" rib=""bar"">"+..
111 "<b>Hello</b></scilab:a></root>"
114 // We search for element named a
115 xmlXPath(doc, "//a") // => nothing
116 xmlXPath(doc, "//scilab:a", ["scilab" "http://www.scilab.org"]) // => OK
118 // This code will fail:
119 // xmlXPath(doc, "//scilab:a") // => error
123 // Query starting on an element
124 t = "<root att=""attribute""><a a1=""A1"" a2=""A2"" a3=""A3"">"+..
125 "<b>Hello</b><c>Scilab</c><b>World</b></a><b>Nothing</b></root>"
127 e = doc.root.children(1);
129 // Get the attributes of e
130 xp = xmlXPath(e, "@*");
133 // Get the 'b' from e
134 xp = xmlXPath(e, "b");
140 <emphasis role="bold">Getting the XML comments:</emphasis>
142 <programlisting ole="example"><![CDATA[
143 doc = xmlRead(SCI+"/modules/ui_data/etc/newsfeed.xml");
144 c = xmlXPath(doc, "//comment()"); // do not forget the trailing ()
153 ! automatic news change interval time (in ms), set to -1 to disable !
154 ! periodic feed update interval time (in ms), set to -1 to disable !
157 <refsection role="see also">
158 <title>See also</title>
159 <simplelist type="inline">
161 <ulink url="http://www.w3.org/TR/1999/REC-xpath-19991116/">W3C XPath recommandation</ulink>
164 <ulink url="https://www.w3schools.com/xml/xpath_intro.asp">XPath tutorial</ulink>
169 <title>History</title>
172 <revnumber>5.4.0</revnumber>
173 <revremark>XML module introduced.</revremark>