1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
5 * Copyright (C) 2017 - Samuel GOUGEON
7 * Copyright (C) 2012 - 2016 - Scilab Enterprises
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
17 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
18 xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
19 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
20 xmlns:scilab="http://www.scilab.org" xml:id="xmlGetValues" xml:lang="en">
22 <refname>xmlGetValues</refname>
23 <refpurpose>Parses and gets values of chosen tags attributes in a XML file of preferences</refpurpose>
28 Values = xmlGetValues(path2tag, attributes)
29 Values = xmlGetValues(path2tag, attributes, XMLsource)
33 <title>Arguments</title>
39 unique string: in the XML source file, path targeting a chosen tag whose
40 attributes must be read. The path is the list of nested tags leading to the
41 required one, such as <literal>"/a/b/c/d"</literal>, or equivalently
42 <literal>"//b/c/d"</literal>. It is case-sensitive.
47 <term>attributes</term>
50 vector or matrix of strings: names of attributes of the chosen tag, whose values
51 must be read. The order of attributes does not matter wrt their actual order in
56 Attributes names are case-sensitive.
59 If needed, the name of a given attribute may be specified several times.
67 <term>XMLsource</term>
70 points to the XML document from which informations must be extracted. It
71 can be one of the following:
74 unique string: path to the XML source file. By default, the main
76 <literal>SCIHOME+'/XConfiguration.xml'</literal> is considered.
79 XML handle of type <literal>XMLdoc</literal>, as returned by a
80 prior <code>xmlRead(XMLsource)</code> external instruction.
90 matrix of strings: Values of the chosen attributes of the chosen tag:
93 If the set of chosen <varname>attributes</varname> is provided as a
94 matrix with several rows, then only the first occurrence of the chosen
95 tag is considered, and <varname>Values(i,j)</varname> is the value of
96 its <varname>attributes(i,j)</varname>.
99 Otherwise, if the names of <varname>attributes</varname> are
100 provided in a row vector, then
101 <emphasis role="italic">all occurences</emphasis> of the chosen tag
102 are considered: Results are returned with one row per occurrence,
103 and one colum per attribute. Thus, <varname>Values(i,j)</varname>
104 is the value of the <varname>attributes(j)</varname> for the
106 i<superscript>th</superscript>
112 If some final values are expected to be numeric rather than literal (text),
113 <code>evstr()</code> may be applied to them to get expected numbers.
120 <title>Description</title>
122 When an XML handle returned by <code>xmlRead(..)</code> is provided as
123 <varname>XMLsource</varname>, <function>xmlGetValues()</function> uses it
124 directly to parse the XML Preferences document opened by this prior
125 <code>xmlRead(..)</code>. This is useful when the same document must be parsed with
126 multiple calls to <function>xmlGetValues()</function>, typically to address
127 different XML tags. In this case, one should not forget to close the XML document after
128 its whole processing.
131 When the path of the XML Preferences file is provided as <varname>XMLsource</varname>,
132 <function>xmlGetValues()</function> opens the file, builds its DOM tree, parses
133 the tree for the chosen tag and attributes, and finally deletes the tree and closes the
134 file before returning results. This is what occurs with the default Xconfiguration.xml
135 file when no explicit <varname>XMLsource</varname> is specified.
138 The <varname>path2tag</varname> argument must be a valid "XPath" according to the
139 <ulink url="https://www.w3.org/TR/1999/REC-xpath-19991116/">W3C recommandations</ulink>.
140 Examples are given herebelow. If the path uses a intermediate or a final tag that does
141 not exist, or if one of the queried attributes does not exist, an error is yielded.
145 <title>Examples</title>
146 <emphasis role="bold">Example 1:</emphasis>
148 Your web and proxy settings for Scilab are stored in the default
149 <literal>SCIHOME+'/XConfiguration.xml'</literal> preferences file. Let's consider the
150 following excerpt of the file:
151 <programlisting role="xml"><![CDATA[
152 <?xml version="1.0" encoding="utf-8" standalone="no"?>
153 <interface height="600" path="1/" version="0.17" width="800">
154 <general title="_(General)">
159 <web command-browser="" command-mailer="" default-browser="true" default-mailer="true"/>
160 <proxy enabled="false" host="" password="" port="" user=""/>
161 <previous-proxy enabled="false" host="" password="" port="" user=""/>
169 To get some informations about the proxy parameters (proxy tag), the required code
171 <programlisting role="scilab"><![CDATA[
172 proxy = xmlGetValues("//web/body/proxy", ["enabled", "host", "port"]);
176 <emphasis role="bold">Example 2:</emphasis>
179 <function>xmlGetValues()</function> can also be used to get values of a tag
180 having multiple occurrences in the <literal>XMLsource</literal> file. For instance,
181 your preferences for the Scilab's editor Scinotes are stored in the
182 <literal>SCIHOME\scinotesConfiguration.xml</literal> file. The list of most recent files
183 opened in Scinotes is stored in the following part and path:
184 <programlisting role="xml"><![CDATA[
185 <?xml version="1.0" encoding="utf-8" standalone="no"?>
186 <Setting version="0.42">
187 <!-- SCINOTES configuration -->
188 <Profile name="scinotes">
190 <!-- Recent Opened Files Section -->
192 <document path="C:\Path\to\my\first\working\dir\ged_move_entity.sci"/>
193 <document path="C:\Path\to\my\first\working\dir\ged_loop.sci"/>
194 <document path="C:\Path\to\my\first\working\dir\test_legend_move.sce"/>
195 <document path="C:\Path\to\another\working\dir2\clf.sci"/>
203 Then, the following code will extract, return and display the column of recent files:
204 <programlisting role="example"><![CDATA[
205 scinotesFile = SCIHOME + "/scinotesConfiguration.xml";
206 recent = xmlGetValues("//Setting/Profile/recentFiles/document", "path", scinotesFile);
207 mprintf("%s\n", recent)
210 C:\Path\to\my\first\working\dir\ged_move_entity.sci
211 C:\Path\to\my\first\working\dir\ged_loop.sci
212 C:\Path\to\my\first\working\dir\test_legend_move.sce
213 C:\Path\to\another\working\dir2\clf.sci
217 <refsection role="see also">
218 <title>See also</title>
219 <simplelist type="inline">
221 <link linkend="xmlSetValues">xmlSetValues</link>
224 <link linkend="xmlXPath">xmlXPath</link>
227 <ulink url="https://www.w3.org/TR/1999/REC-xpath-19991116/">XML path language</ulink>
230 <link linkend="xmlRead">xmlRead</link>
233 <link linkend="xmlDelete">xmlDelete</link>
236 <link linkend="atomsGetConfig">atomsGetConfig</link>
239 <link linkend="printsetupbox">printsetupbox</link>
242 <link linkend="csvDefault">csvDefault</link>
246 <refsection role="history">
247 <title>History</title>
250 <revnumber>6.0.2</revnumber>
251 <revdescription>xmlGetValues() introduced, was formerly getPreferencesValue().