Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.1 - Português

Change language to:
English - Français - 日本語 - Русский

Please note that the recommended version of Scilab is 2024.1.0. This page might be outdated.
However, this page did not exist in the previous stable version.

Ajuda do Scilab >> Preferences > getPreferencesValue


Parses and gets values of chosen tags attributes in a XML file of preferences


Values = getPreferencesValue(path2tag, attributes)
Values = getPreferencesValue(path2tag, attributes, XMLsource)



unique string: in the XML source file, path targeting a chosen tag whose attributes must be read. The path is the list of nested tags leading to the required one, such as "/a/b/c/d", or equivalently "//b/c/d". It is case-sensitive.


vector or matrix of strings: names of attributes of the chosen tag, whose values must be read. The order of attributes does not matter wrt their actual order in the tag.

  • Attributes names are case-sensitive.
  • If needed, the name of a given attribute may be specified several times.


points to the XML document from which informations must be extracted. It can be one of the following:

  • unique string: path to the XML source file (where preferences are registered). By default, SCIHOME+'/XConfiguration.xml' is considered.
  • XML handle of type XMLdoc, as returned by a prior xmlRead(XMLsource) external instruction.


matrix of strings: Values of the chosen attributes of the chosen tag:

  • If the set of chosen attributes is provided as a matrix with several rows, then only the first occurrence of the chosen tag is considered, and Values(i,j) is the value of its attributes(i,j).
  • Otherwise, if the names of attributes are provided in a row vector, then all occurences of the chosen tag are considered: Results are returned with one row per occurrence, and one colum per attribute. Thus, Values(i,j) is the value of the attributes(j) for the ith occurrence of the tag in the document.
If some final values are expected to be numeric rather than literal (text), evstr() may be applied to them to get expected numbers.


When an XML handle returned by xmlRead(..) is provided as XMLsource, getPreferencesValue() uses it directly to parse the XML Preferences document opened by this prior xmlRead(..). This is useful when the same document must be parsed with multiple calls to getPreferencesValue(), typically to address different XML tags. In this case, one should not forget to close the XML document after its whole processing.

When the path of the XML Preferences file is provided as XMLsource, getPreferencesValue() opens the file, builds its DOM tree, parses the tree for the chosen tag and attributes, and finally deletes the tree and closes the file before returning results. This is what occurs with the default Xconfiguration.xml file when no explicit XMLsource is specified.

The path2tag argument must be a valid "XPath" according to the W3C recommandations. Examples are given herebelow. If the path uses a intermediate or a final tag that does not exist, or if one of the queried attributes does not exist, an error is yielded.


Example 1:

Your web and proxy settings for Scilab are stored in the default SCIHOME+'/XConfiguration.xml' preferences file. Let's consider the following excerpt of the file:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<interface height="600" path="1/" version="0.17" width="800">
    <general title="_(General)">
    <web title="_(Web)">
            <web command-browser="" command-mailer="" default-browser="true" default-mailer="true"/>
            <proxy enabled="false" host="" password="" port="" user=""/>
            <previous-proxy enabled="false" host="" password="" port="" user=""/>

To get some informations about the proxy parameters (proxy tag), the required code will be:

proxy = getPreferencesValue("//web/body/proxy", ["enabled", "host", "port"]);

Example 2:

getPreferencesValue() can also be used to get values of a tag having multiple occurrences in the XMLsource file. For instance, your preferences for the Scilab's editor Scinotes are stored in the SCIHOME\scinotesConfiguration.xml file. The list of most recent files opened in Scinotes is stored in the following part and path:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Setting version="0.42">
    <!-- SCINOTES configuration -->
    <Profile name="scinotes">
        <!-- .../... -->
        <!-- Recent Opened Files Section  -->
            <document path="C:\Path\to\my\first\working\dir\ged_move_entity.sci"/>
            <document path="C:\Path\to\my\first\working\dir\ged_loop.sci"/>
            <document path="C:\Path\to\my\first\working\dir\test_legend_move.sce"/>
            <document path="C:\Path\to\another\working\dir2\clf.sci"/>
        <!-- .../... -->

Then, the following code will extract, return and display the column of recent files:

scinotesFile = SCIHOME + "/scinotesConfiguration.xml";
recent = getPreferencesValue("//Setting/Profile/recentFiles/document", "path", scinotesFile);
mprintf("%s\n", recent)

See also


5.5.0 getPreferencesValue() introduced.
  • XMLsource can now be the path + filename of the preferences file.
  • A tag with multiple occurrences can now be read.
Report an issue
<< Preferences Preferences preferences >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Feb 12 19:58:46 CET 2018