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
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