modify xml using javascript

ONeFoSToRy

New Member
I am starting to learn xml and I am facing a problem. I need to add elements to the xml file so I use this method:\[code\]function newNode() { var xmlDoc = loadXMLDoc("Nodes.xml"); var nodes = xmlDoc.documentElement; var newNode = xmlDoc.createElement('node'); var newName = xmlDoc.createElement('name'); var newText = xmlDoc.createTextNode('Start Node'); newName.appendChild(newText); newNode.appendChild(newName); xmlDoc.documentElement.appendChild(newNode); alert(xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue); return xmlDoc;}\[/code\]it works fine and the alert shows "Start Node", but when I use the same alert command as in:\[code\]function z() { var xmlDoc = loadXMLDoc("Nodes.xml"); alert(xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue);}\[/code\]I get this error: Unable to get value of the property 'childNodes': object is null or undefined.
 
Back
Top