Using Javascript to dynamically change xml file content error

S

steve stevo

I am trying to dynamically change an xml file


this is the xml file

<school>
<teacher>
<name>Mr Wallis</name>
<subject>Geography</subject>
<level>A level</level>
</teacher>
<teacher>
<name>Mr Green</name>
<subject>Physics</subject>
<level>GCSE</level>
</teacher>
</school>

etc

I would like to be able to dynamically change the value of selected nodes


function upStaff(tName,i,x){
var xmlDoc = new ActiveXObject("msxml2.DOMDocument.4.0");

xmlDoc.async=false;xmlDoc.resolveExternals=false;
xmlDoc.validateOnParse=false;

xmlDoc.load("xml/staff.xml");

nodes=xmlDoc.selectNodes("/school/teacher[name='" + tName + "']/*")

var oNode = nodes.item(i);

oNode.nodeValue = x;

xmlDoc.save("xml/staff.xml");
}


and call using

upStaff('Mr Wallis',0,'Mr Williams') // this should change the teachers
name

or

upStaff('Mr Wallis',1,'French') // This should change the teachers subject

this displays an error

"This operation can not be performed with a node of type element."

Im lost - please help

Thanks in advance.

Simon Christie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top