* Bug 16148: xmlSetValues() <= setPreferencesValue() 38/21038/4
Samuel GOUGEON [Thu, 18 Jul 2019 13:59:57 +0000 (15:59 +0200)]
  http://bugzilla.scilab.org/16148

Change-Id: I5610ab0b0d70b3f06ad92fdb2a68786837f80eca

21 files changed:
scilab/CHANGES.md
scilab/modules/atoms/macros/atomsRestoreConfig.sci
scilab/modules/atoms/macros/atomsSaveConfig.sci
scilab/modules/atoms/macros/atomsSetConfig.sci
scilab/modules/demo_tools/macros/demo_gui.sci
scilab/modules/elementary_functions/help/en_US/floating_point/ieee.xml
scilab/modules/elementary_functions/help/fr_FR/floating_point/ieee.xml
scilab/modules/elementary_functions/help/ja_JP/floating_point/ieee.xml
scilab/modules/elementary_functions/help/pt_BR/floating_point/ieee.xml
scilab/modules/elementary_functions/help/ru_RU/floating_point/ieee.xml
scilab/modules/helptools/data/configuration/scilab_macros.txt
scilab/modules/preferences/help/en_US/getPreferencesValue.xml
scilab/modules/preferences/help/en_US/setPreferencesValue.xml
scilab/modules/preferences/help/ja_JP/getPreferencesValue.xml
scilab/modules/preferences/help/ja_JP/setPreferencesValue.xml
scilab/modules/preferences/macros/setPreferencesValue.sci
scilab/modules/slint/src/cpp/DeprecatedChecker.cpp
scilab/modules/xml/help/en_US/xmlGetValues.xml
scilab/modules/xml/help/en_US/xmlSetValues.xml [new file with mode: 0644]
scilab/modules/xml/help/ja_JP/xmlGetValues.xml
scilab/modules/xml/macros/xmlSetValues.sci [new file with mode: 0644]

index b27f19f..0a6e435 100644 (file)
@@ -119,6 +119,7 @@ Feature changes and additions
 * `csvRead` and `csvTextScan` are now implemented without extra copies.
 * `editvar()` GUI support copy-paste of strings removing quotes.
 * calendar() can now display formated calendars.
+* `xmlSetValues()` clones `setPreferencesValue` that is now obsolete.
 
 
 Help pages:
@@ -150,6 +151,7 @@ Obsolete functions or features
 ------------------------------
 * `frexp` becomes an internal. Please use `[m,e]=log2(x)` instead.
 * `champ1()` is obsolete. Please use `champ.colored` instead.
+* `setPreferencesValue` will be removed from Scilab 6.1.x. Please use `xmlSetValues` instead.
 
 
 Removed Functions
@@ -251,6 +253,7 @@ Bug Fixes
 * [#16139](http://bugzilla.scilab.org/show_bug.cgi?id=16139): `auread()` and `auwrite()` kept the sound file open and locked when returning on errors. They poorly handled the default .au sound file extension.
 * [#16143](http://bugzilla.scilab.org/show_bug.cgi?id=16143): `clc(n)` cleared n+1 lines instead of n>0. Thus, it was not possible to clear only one line.
 * [#16144](http://bugzilla.scilab.org/show_bug.cgi?id=16144): Addition of sparse matrices gave incorrect results.
+* [#16148](http://bugzilla.scilab.org/show_bug.cgi?id=16148): `setPreferencesValue` is a general usage function and deserved to be renamed `xmlSetValues`.
 * [#16149](http://bugzilla.scilab.org/show_bug.cgi?id=16149): `fullpath` did not support symbolic links in paths
 * [#16152](http://bugzilla.scilab.org/show_bug.cgi?id=16152): For sparse or boolean sparse matrix `s`, `s([])` returned `[]` instead of `sparse([])`.
 * [#16158](http://bugzilla.scilab.org/show_bug.cgi?id=16158): When a multicolumn array of rationals was displayed wide column per column, columns #2:$ were replaced with its column #2.
@@ -277,3 +280,4 @@ Bug Fixes
 * [#16293](http://bugzilla.scilab.org/show_bug.cgi?id=16293): Some demos run in step-by-step console mode(4) did not focus user's attention to the console to proceed.
 * [#16299](http://bugzilla.scilab.org/show_bug.cgi?id=16299): After `graypolarplot()`, `colorbar()` displayed an empty ungraduated color bar.
 * [#16303](http://bugzilla.scilab.org/show_bug.cgi?id=16303): log10(x) had wrong dimensions when x is an hypermatrix.
+
index 4a484f6..409d3c7 100644 (file)
@@ -27,7 +27,7 @@ function atomsRestoreConfig(quiet)
     end
 
     proxy_attrs = ["enabled", "host", "port", "user", "password"];
-    setPreferencesValue("//web/body/proxy", [proxy_attrs ; xmlGetValues("//web/body/previous-proxy", proxy_attrs)]);
+    xmlSetValues("//web/body/proxy", [proxy_attrs ; xmlGetValues("//web/body/previous-proxy", proxy_attrs)]);
 
     pathsystemuser = atomsPath("system", "user");
 
index d47cb3c..1f5f378 100644 (file)
@@ -29,7 +29,7 @@ function atomsSaveConfig(force)
     pathsystemuser = atomsPath("system", "user");
 
     proxy_attrs = ["enabled", "host", "port", "user", "password"];
-    setPreferencesValue("//web/body/previous-proxy", [proxy_attrs ; xmlGetValues("//web/body/proxy", proxy_attrs)]);
+    xmlSetValues("//web/body/previous-proxy", [proxy_attrs ; xmlGetValues("//web/body/proxy", proxy_attrs)]);
 
     if isfile(pathsystemuser + "config.bak") then
         if ~force then
index 75e3991..bdf5b59 100644 (file)
@@ -143,7 +143,7 @@ function nbChanges = atomsSetConfig(field, value)
     end
 
     if ~isempty(prefs_kv) then
-        setPreferencesValue("//web/body/proxy", prefs_kv);
+        xmlSetValues("//web/body/proxy", prefs_kv);
     end
 
     // Shortcut
index cb94ccb..434f4c0 100644 (file)
@@ -57,11 +57,11 @@ function demo_gui()
         if ~isfile(File2) then
             r = copyfile(File, File2);
             doc = xmlRead(File2);
-            setPreferencesValue("/scilabgui/figure", ..
-                                ["dockable" "on"
-                                 "infobar_visible" "on"
-                                 "menubar" "figure"
-                                 "menubar_visible" "on"]', doc);
+            xmlSetValues("/scilabgui/figure", ..
+                         ["dockable" "on"
+                          "infobar_visible" "on"
+                          "menubar" "figure"
+                          "menubar_visible" "on"]', doc);
             xmlWrite(doc);
             xmlDelete(doc);
         end
index 12d4a67..30394df 100644 (file)
                   <emphasis role="italic">General => Environment => ieee</emphasis>.
                 </listitem>
                 <listitem>
-                  Equivalently, using <code>setPreferencesValue</code> as follows
+                  Equivalently, using <code>xmlSetValues</code> as follows
                   (to set the mode to 1) :
                   <para>
-                  <literal>setPreferencesValue("//general/body/environment", ["fpe";"1"])</literal>
+                  <literal>xmlSetValues("//general/body/environment", ["fpe";"1"])</literal>
                   </para>
                 </listitem>
                 <listitem>
index 7ffab1f..e3861cf 100644 (file)
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="fr" xml:id="ieee">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
+          xml:lang="fr" xml:id="ieee">
     <refnamediv>
         <refname>ieee</refname>
         <refpurpose>fixe ou indique le mode d'exception IEEE pour les calculs</refpurpose>
@@ -80,9 +83,9 @@
                   <emphasis role="italic">Général => Environment => ieee</emphasis>.
                 </listitem>
                 <listitem>
-                  En utilisant <code>setPreferencesValue</code> comme suit (ici pour ieee(1)) :
+                  En utilisant <code>xmlSetValues</code> comme suit (ici pour ieee(1)) :
                   <para>
-                  <literal>setPreferencesValue("//general/body/environment", ["fpe";"1"])</literal>
+                  <literal>xmlSetValues("//general/body/environment", ["fpe";"1"])</literal>
                   </para>
                 </listitem>
                 <listitem>
index 31d89ba..2268966 100644 (file)
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="ieee" xml:lang="ja">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+          xmlns:scilab="http://www.scilab.org" xml:id="ieee" xml:lang="ja">
     <refnamediv>
         <refname>ieee</refname>
         <refpurpose>浮動小数点例外モードを設定</refpurpose>
                   <emphasis role="italic">General => Environment => ieee</emphasis>.
                 </listitem>
                 <listitem>
-                  Equivalently, using <code>setPreferencesValue</code> as follows
-                  (to set the mode to 1) :
+                  Equivalently, using <code>xmlSetValues</code> as follows (to set the mode to 1) :
                   <para>
-                  <literal>setPreferencesValue("//general/body/environment", ["fpe";"1"])</literal>
+                  <literal>xmlSetValues("//general/body/environment", ["fpe";"1"])</literal>
                   </para>
                 </listitem>
                 <listitem>
index 65b0396..5661889 100644 (file)
                   <emphasis role="italic">General => Environment => ieee</emphasis>.
                 </listitem>
                 <listitem>
-                  Equivalently, using <code>setPreferencesValue</code> as follows
-                  (to set the mode to 1) :
+                  Equivalently, using <code>xmlSetValues</code> as follows (to set the mode to 1) :
                   <para>
-                  <literal>setPreferencesValue("//general/body/environment", ["fpe";"1"])</literal>
+                  <literal>xmlSetValues("//general/body/environment", ["fpe";"1"])</literal>
                   </para>
                 </listitem>
                 <listitem>
index 7a1cdfb..81bbe98 100644 (file)
                   <emphasis role="italic">Общие => Рабочая среда => ieee</emphasis>.
                 </listitem>
                 <listitem>
-                  Аналогично, используя <code>setPreferencesValue</code> следующим образом
+                  Аналогично, используя <code>xmlSetValues</code> следующим образом
                   (чтобы установить режим в 1) :
                   <para>
-                  <literal>setPreferencesValue("//general/body/environment", ["fpe";"1"])</literal>
+                  <literal>xmlSetValues("//general/body/environment", ["fpe";"1"])</literal>
                   </para>
                 </listitem>
                 <listitem>
index 177ef90..9349fd5 100644 (file)
@@ -227,7 +227,7 @@ C:\Path\to\another\working\dir2\clf.sci
                 <link linkend="xmlGetValues">xmlGetValues</link>
             </member>
             <member>
-                <link linkend="setPreferencesValue">setPreferencesValue</link>
+                <link linkend="xmlSetValues">xmlSetValues</link>
             </member>
             <member>
                 <link linkend="xmlXPath">xmlXPath</link>
index 8217a4a..2920b91 100644 (file)
@@ -16,7 +16,7 @@
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="setPreferencesValue" xml:lang="en">
     <refnamediv>
         <refname>setPreferencesValue</refname>
-        <refpurpose>Set preferences value</refpurpose>
+        <refpurpose>Set preferences value <emphasis role="bold">(obsolete)</emphasis></refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
     </refsection>
     <refsection>
         <title>Description</title>
+        <warning>
+            <literal>setPreferencesValue()</literal> is obsolete and will be removed in Scilab 6.1.x.
+            Please use <code>xmlSetValues()</code> instead.
+        </warning>
         <para>
             Set the values of the attributes in preferences file (<literal>SCIHOME+'/XConfiguration.xml'</literal>).
         </para>
@@ -84,7 +88,7 @@
     </web>
     ...
 </interface>
-             ]]></programlisting>
+          ]]></programlisting>
                 <para>
                     The path will be <literal>"/interface/web/body/proxy"</literal> (or to simplify <literal>"//web/body/proxy"</literal>).
                 </para>
@@ -114,4 +118,15 @@ xmlGetValues("//web/body/proxy", ["enabled", "host", "port"])
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    setPreferencesValue() declared obsolete, replaced with xmlSetValues().
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 6813d4a..8678c28 100644 (file)
@@ -118,7 +118,7 @@ getPreferencesValue("//web/body/proxy", ["enabled", "host", "port"]);
                 <link linkend="xmlGetValues">xmlGetValues</link>
             </member>
             <member>
-                <link linkend="setPreferencesValue">setPreferencesValue</link>
+                <link linkend="xmlSetValues">xmlSetValues</link>
             </member>
         </simplelist>
     </refsection>
index d29415a..8a9ccf4 100644 (file)
@@ -16,7 +16,7 @@
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="setPreferencesValue" xml:lang="ja">
     <refnamediv>
         <refname>setPreferencesValue</refname>
-        <refpurpose>設定値を設定</refpurpose>
+        <refpurpose>設定値を設定 <emphasis role="bold">(obsolete)</emphasis></refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>呼び出し手順</title>
     </refsection>
     <refsection>
         <title>説明</title>
+        <warning>
+            <literal>setPreferencesValue()</literal> is obsolete and will be removed in Scilab 6.1.x.
+            Please use <code>xmlSetValues()</code> instead.
+        </warning>
         <para>
             設定ファイル(<literal>SCIHOME+'/XConfiguration.xml'</literal>)
             の属性の値を設定します.
     </web>
     ...
 </interface>
-             ]]></programlisting>
+          ]]></programlisting>
                 <para>
                     パスは<literal>"/interface/web/body/proxy"</literal>
                     (または簡単化するために<literal>"//web/body/proxy"</literal>)
@@ -126,4 +130,15 @@ xmlGetValues("//web/body/proxy", ["enabled", "host", "port"])
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>履歴</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    setPreferencesValue() declared obsolete, replaced with xmlSetValues().
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 05d3d20..c6d7ec3 100644 (file)
@@ -18,6 +18,8 @@
 //                   (take care: in this case xmlWrite is not called)
 //
 function setPreferencesValue(xpath, kv, doc)
+
+    warnobsolete("xmlSetValues()", "6.1.x")
     rhs = argn(2);
 
     if (rhs ~= 2 & rhs ~= 3) then
index 4f5e86f..72f853b 100644 (file)
@@ -93,6 +93,9 @@ std::unordered_map<std::wstring, std::wstring> DeprecatedChecker::initDep()
     // TODO: get this list from a conf file
     std::unordered_map<std::wstring, std::wstring> map;
 
+    // Scilab 6.1.0 => 6.1.x
+    map.emplace(L"setPreferencesValue", L"xmlSetValues");
+
     // Scilab 6.0.x => 6.1.0
     map.emplace(L"champ1", L"champ.colored");
     map.emplace(L"dirname", L"fileparts");
index 2b47355..24e03e9 100644 (file)
@@ -218,7 +218,7 @@ C:\Path\to\another\working\dir2\clf.sci
         <title>See also</title>
         <simplelist type="inline">
             <member>
-                <link linkend="setPreferencesValue">setPreferencesValue</link>
+                <link linkend="xmlSetValues">xmlSetValues</link>
             </member>
             <member>
                 <link linkend="xmlXPath">xmlXPath</link>
diff --git a/scilab/modules/xml/help/en_US/xmlSetValues.xml b/scilab/modules/xml/help/en_US/xmlSetValues.xml
new file mode 100644 (file)
index 0000000..baa7e30
--- /dev/null
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2019 - Samuel GOUGEON
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+          xmlns:scilab="http://www.scilab.org" xml:id="xmlSetValues" xml:lang="en">
+    <refnamediv>
+        <refname>xmlSetValues</refname>
+        <refpurpose>Sets some attribute=value in an XML document for a given tag/XPath</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Syntax</title>
+        <synopsis>
+            xmlSetValues(xpath, attributes_values)
+            xmlSetValues(xpath, attributes_values, doc)
+        </synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>xpath</term>
+                <listitem>
+                    <para>a string: XPath request pointing to the chosen tag in the XML document.</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>attributes_values</term>
+                <listitem>
+                    <para>a 2xN matrix of strings: the (attribute,value) pairs to set.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+        <variablelist>
+            <varlistentry>
+                <term>doc</term>
+                <listitem>
+                    <para>
+                        mlist typed XMLDoc: the XML document in which to write values.
+                        By default, it is the main Scilab preferences file
+                        (<literal>SCIHOME + '/XConfiguration.xml'</literal>).
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            When no explicit XML document <varname>doc</varname> is indicated,
+            <literal>xmlSetValues</literal> opens the main Scilab preferences file
+            <literal>SCIHOME + '/XConfiguration.xml'</literal>, looks for the tag pointed to by
+            <varname>xpath</varname>, updates some of its attributes and related values as
+            provided by <varname>attributes_values</varname>, and closes the file.
+        </para>
+        <para>
+            <literal>xmlSetValues</literal> can also be used on-the-fly on an already open XML
+            document <varname>doc</varname>. In this case, the document is kept open after
+            leaving <literal>xmlSetValues</literal>. This mode is useful when several
+            tags must be updated in the same document.
+        </para>
+        <para>
+            Attributes to update must already exist for the given tag.
+            <literal>xmlSetValues</literal> is not able to create new ones.
+        </para>
+        <para>
+            All valid XPath requests are possible. For example to write the XPath request to
+            set proxy settings in the main Scilab configuration file:
+        </para>
+        <simplelist type="inline">
+            <member>
+                <para>
+                    Opens <literal>SCIHOME+'/XConfiguration.xml'</literal> and gets the
+                    nodes names to access to the expected node:
+                </para>
+                <programlisting role="xml"><![CDATA[
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<interface height="600" path="1/" version="0.17" width="800">
+    <general title="_(General)">
+    ...
+    </general>
+    <web title="_(Web)">
+        <body>
+            <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=""/>
+        </body>
+    </web>
+    ...
+</interface>
+          ]]></programlisting>
+                <para>
+                    The path will be <literal>"/interface/web/body/proxy"</literal>
+                    (or to simplify <literal>"//web/body/proxy"</literal>).
+                </para>
+            </member>
+        <warning>
+            Modifying incorrectly some preferences can alter the Scilab's behaviour.
+        </warning>
+        </simplelist>
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+// Get the current values
+prev = xmlGetValues("//web/body/proxy", ["enabled", "host", "port"]);
+xmlSetValues("//web/body/proxy", ["enabled", "host", "port"; "true", "my.proxy.org", "1234"]);
+
+// Ok that's work
+xmlGetValues("//web/body/proxy", ["enabled", "host", "port"])
+
+// We restore the previous values
+xmlSetValues("//web/body/proxy", ["enabled", "host", "port" ; prev]);
+xmlGetValues("//web/body/proxy", ["enabled", "host", "port"])
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="xmlGetValues">xmlGetValues</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    xmlSetValues() introduced, replacing setPreferencesValue().
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
index bae3a21..b567e25 100644 (file)
  * along with this program.
  *
  -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="xmlGetValues" xml:lang="ja">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+          xmlns:scilab="http://www.scilab.org" xml:id="xmlGetValues" xml:lang="ja">
     <refnamediv>
         <refname>xmlGetValues</refname>
         <refpurpose>設定値を取得</refpurpose>
@@ -55,7 +58,7 @@
     </refsection>
     <refsection>
         <title>説明</title>
-               <warning>This page is not up-to-date. Please consider the english version.</warning>
+        <warning>This page is not up-to-date. Please consider the english version.</warning>
         <para>
             設定ファイル(<literal>SCIHOME+'/XConfiguration.xml'</literal>)の
             属性の値を取得します.
@@ -93,7 +96,7 @@
     </web>
     ...
 </interface>
-             ]]></programlisting>
+          ]]></programlisting>
                 <para>
                     パスは<literal>"/interface/web/body/proxy"</literal>
                     (または簡単化するために<literal>"//web/body/proxy"</literal>)
@@ -112,7 +115,7 @@ xmlGetValues("//web/body/proxy", ["enabled", "host", "port"]);
         <title>参照</title>
         <simplelist type="inline">
             <member>
-                <link linkend="setPreferencesValue">setPreferencesValue</link>
+                <link linkend="xmlSetValues">xmlSetValues</link>
             </member>
         </simplelist>
     </refsection>
diff --git a/scilab/modules/xml/macros/xmlSetValues.sci b/scilab/modules/xml/macros/xmlSetValues.sci
new file mode 100644 (file)
index 0000000..d4e86e9
--- /dev/null
@@ -0,0 +1,91 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
+// Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2019 - Samuel GOUGEON
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// This file was originally licensed under the terms of the CeCILL v2.1,
+// and continues to be available under such terms.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+
+function xmlSetValues(xpath, kv, doc)
+       // Sets attribute=values pairs for a given tag in a XML document.
+       // - xpath is something like "//web/body/proxy", the target must be a single node/tag
+       // - kv is a matrix of strings 2xN: keys are in the first row and values in the
+       //   seconde one.
+       // - doc (optional): the prefs xml document where to set the values
+       //                   (take care: in this case xmlWrite is not called)
+       //
+    rhs = argn(2);
+       fname = "xmlSetValues"
+
+    if (rhs ~= 2 & rhs ~= 3) then
+        error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"), fname, 2, 3));
+    end
+
+    if type(xpath) <> 10 then
+        error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1));
+    end
+
+    if type(kv) <> 10 then
+        error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), fname, 2));
+    end
+
+    if (size(kv, "r") ~= 2) then
+        error(msprintf(gettext("%s: Wrong size for input argument #%d: a 2xN matrix expected.\n"), fname, 2));
+    end
+
+    if rhs == 2 then
+        try
+            doc = xmlRead(SCIHOME + "/XConfiguration.xml");
+        catch
+            error(msprintf(gettext("%s: Invalid XConfiguration.xml file.\n"), fname));
+        end
+    elseif typeof(doc) ~= "XMLDoc" then
+        error(msprintf(gettext("%s: Wrong type for input argument #%d: A XMLDoc expected.\n"), fname, 3));
+    end
+
+    try
+        xp = xmlXPath(doc, xpath);
+    catch
+        if rhs == 2 then
+            xmlDelete(doc);
+        end
+        error(msprintf(gettext("%s: Invalid XPath request.\n"), fname));
+    end
+
+    if xp.size ~= 1 then
+        if rhs == 2 then
+            xmlDelete(doc);
+        end
+        error(msprintf(gettext("%s: Invalid XPath request."), fname));
+    end
+
+    node = xp(1);
+    if node.type ~= "XML_ELEMENT_NODE" then
+        if rhs == 2 then
+            xmlDelete(doc);
+        end
+        error(msprintf(gettext("%s: Target node is not a XML_ELEMENT_NODE."), fname));
+    end
+
+    attr = node.attributes;
+    for i = 1:size(kv, "c")
+        v = attr(kv(1, i));
+        if v ~= [] then
+            attr(kv(1, i)) = kv(2, i);
+        else
+            if rhs == 2 then
+                xmlDelete(doc);
+            end
+            error(msprintf(gettext("%s: Invalid attribute name: %s."), fname, kv(1, i)));
+        end
+    end
+
+    if rhs == 2 then
+        xmlWrite(doc);
+        xmlDelete(doc);
+    end
+endfunction