anatar02
12 years agoContributor
How to set the value based on the "childNode" in xml
Hi All,
I am working on the xml formate files where i need to update the node value based on the childNode values which i given!!!
<test>
<qty>test<qty>
</test>
here.... i need to update the node of qty!!! i here reached the node of qty...but i dont know what is method to set the value fro node....
function setNodeValue(childNode,nodeNumber)
{
var xmlDoc, s;
var actualPath="T:\\Config\\Parameters\\params.xml";
// Specify your file name
var FileName = actualPath;
// Load xml file
xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
xmlDoc.load(FileName);
// Check errors
if (xmlDoc.parseError.errorCode != 0)
{
s = "Reason: " + xmlDoc.parseError.reason + "\n" +
"Line: " + xmlDoc.parseError.line + "\n" +
"Text: " + xmlDoc.parseError.srcText;
Log.Error("Failed to open file " + FileName, s);
return;
}
// Specify your XPath expression
var xmlNode = xmlDoc.selectNodes("//"+childNode);
if (xmlNode != null)
{
for (var i = 0; i < xmlNode["length"]; i++)
//Log["Message"](xmlNode.item(i).text);
var actual=xmlNode.item(nodeNumber).text;
return actual;
}
}
please help me how can i update the qty node?
I am working on the xml formate files where i need to update the node value based on the childNode values which i given!!!
<test>
<qty>test<qty>
</test>
here.... i need to update the node of qty!!! i here reached the node of qty...but i dont know what is method to set the value fro node....
function setNodeValue(childNode,nodeNumber)
{
var xmlDoc, s;
var actualPath="T:\\Config\\Parameters\\params.xml";
// Specify your file name
var FileName = actualPath;
// Load xml file
xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
xmlDoc.load(FileName);
// Check errors
if (xmlDoc.parseError.errorCode != 0)
{
s = "Reason: " + xmlDoc.parseError.reason + "\n" +
"Line: " + xmlDoc.parseError.line + "\n" +
"Text: " + xmlDoc.parseError.srcText;
Log.Error("Failed to open file " + FileName, s);
return;
}
// Specify your XPath expression
var xmlNode = xmlDoc.selectNodes("//"+childNode);
if (xmlNode != null)
{
for (var i = 0; i < xmlNode["length"]; i++)
//Log["Message"](xmlNode.item(i).text);
var actual=xmlNode.item(nodeNumber).text;
return actual;
}
}
please help me how can i update the qty node?
Hi Ashok,
Where do you see the results? Don't forget to save the updated XML file: