Forum Discussion

anatar02's avatar
anatar02
Contributor
12 years ago

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?




  • Hi Ashok,


     


    Where do you see the results? Don't forget to save the updated XML file:




     

  • I think you can do that like this:

    xmlNode.item(nodeNumber).text = "new value";
  • Thanks for your reply !!! 



    but it was not updating the node value!!!
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Ashok,


     


    Where do you see the results? Don't forget to save the updated XML file:




     

  • Thanks for your reply!! 



    but i did not get you!! you mean i need to save the file once i updated by using below code 



    =xmlNode.item(nodeNumber).text="new Value"