1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 // Set preferences values
14 // - xpath is something like "//web/body/proxy", the target must be a single node
15 // - kv is a matrix of strings 2xN: keys are in the first row and values in the
17 // - doc (optional): the prefs xml document where to set the values
18 // (take care: in this case xmlWrite is not called)
20 function setPreferencesValue(xpath, kv, doc)
22 warnobsolete("xmlSetValues()", "6.1.x")
25 if (rhs ~= 2 & rhs ~= 3) then
26 error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"), "setPreferencesValue", 2, 3));
29 if type(xpath) <> 10 then
30 error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "setPreferencesValue", 1));
33 if type(kv) <> 10 then
34 error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), "setPreferencesValue", 2));
37 if (size(kv, "r") ~= 2) then
38 error(msprintf(gettext("%s: Wrong size for input argument #%d: a 2xN matrix expected.\n"), "setPreferencesValue", 2));
43 doc = xmlRead(SCIHOME + "/XConfiguration.xml");
45 error(msprintf(gettext("%s: Invalid XConfiguration.xml file.\n"), "setPreferencesValue"));
47 elseif typeof(doc) ~= "XMLDoc" then
48 error(msprintf(gettext("%s: Wrong type for input argument #%d: A XMLDoc expected.\n"), "setPreferencesValue", 3));
52 xp = xmlXPath(doc, xpath);
57 error(msprintf(gettext("%s: Invalid XPath request.\n"), "setPreferencesValue"));
64 error(msprintf(gettext("%s: Invalid XPath request."), "setPreferencesValue"));
68 if node.type ~= "XML_ELEMENT_NODE" then
72 error(msprintf(gettext("%s: Target node is not a XML_ELEMENT_NODE."), "setPreferencesValue"));
75 attr = node.attributes;
76 for i = 1:size(kv, "c")
79 attr(kv(1, i)) = kv(2, i);
84 error(msprintf(gettext("%s: Invalid attribute name: %s."), "setPreferencesValue", kv(1, i)));