1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
3 // Copyright (C) 2012 - 2016 - Scilab Enterprises
4 // Copyright (C) 2019 - Samuel GOUGEON
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 function xmlSetValues(xpath, kv, doc)
14 // Sets attribute=values pairs for a given tag in a XML document.
15 // - xpath is something like "//web/body/proxy", the target must be a single node/tag
16 // - kv is a matrix of strings 2xN: keys are in the first row and values in the
18 // - doc (optional): the prefs xml document where to set the values
19 // (take care: in this case xmlWrite is not called)
22 fname = "xmlSetValues"
24 if (rhs ~= 2 & rhs ~= 3) then
25 error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"), fname, 2, 3));
28 if type(xpath) <> 10 then
29 error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1));
32 if type(kv) <> 10 then
33 error(msprintf(gettext("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), fname, 2));
36 if (size(kv, "r") ~= 2) then
37 error(msprintf(gettext("%s: Wrong size for input argument #%d: a 2xN matrix expected.\n"), fname, 2));
42 doc = xmlRead(SCIHOME + "/XConfiguration.xml");
44 error(msprintf(gettext("%s: Invalid XConfiguration.xml file.\n"), fname));
46 elseif typeof(doc) ~= "XMLDoc" then
47 error(msprintf(gettext("%s: Wrong type for input argument #%d: A XMLDoc expected.\n"), fname, 3));
51 xp = xmlXPath(doc, xpath);
56 error(msprintf(gettext("%s: Invalid XPath request.\n"), fname));
63 error(msprintf(gettext("%s: Invalid XPath request."), fname));
67 if node.type ~= "XML_ELEMENT_NODE" then
71 error(msprintf(gettext("%s: Target node is not a XML_ELEMENT_NODE."), fname));
74 attr = node.attributes;
75 for i = 1:size(kv, "c")
78 attr(kv(1, i)) = kv(2, i);
83 error(msprintf(gettext("%s: Invalid attribute name: %s."), fname, kv(1, i)));