Using VBScripting Add Node to a xml file



In the following XML file, using vbscript i want the add nodes



<?xml version="1.0"?>
<Project>
<Variable name="Variable_1"/>
<Study>
<Agent>
<Variable name="Variable_1" baseline="0" distribution="" flags="2" max="1" min="0"/>
</Agent>
</Study>
</Project>


After running the script, xml file will be like following.



<?xml version="1.0"?>
<Project>
<Variable name="Variable_1"/>
<Variable name="Variable_2"/>
<Variable name="Variable_3"/>
<Study>
<Agent>
<Variable name="Variable_1" baseline="0" distribution="" flags="2" max="1" min="0"/>
<Variable name="Variable_2" baseline="4" distribution="" flags="2" max="3" min="1"/>
</Agent>
</Study>
</Project>


I tried following codes but no results



Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load("us2.xml")
Dim objCurrNode, objNewNode, objNewText
Set objRoot = xmlDoc.documentElement
Set objNewNode = XMLDoc.createElement("VarIable name")
Set objNewText = XMLDoc.createTextNode("Variable_2")
objNewNode.appendChild(objNewText)
xmlDoc.Save "Audits.xml"


please suggest on this. Thanks.


No comments:

Post a Comment