Hi,
I was trying to insert new node and data into the xml file.
Let say If I am inserting the data from page1 at line 4 and displaying the inserted data at line 5, its displaying it perfectly but when I go to the xml file and look for the inserted data its not there. I am I doing any mistake in the code below????
This is the example from w3schools.com
this goes into ur source
<HTML>
<HEAD>
</HEAD>
<body>
<script language="javas cript">
xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.async=fa lse;
xmlDoc.load("bo oks.xml");
var x=xmlDoc.getEle mentsByTagName( 'book');
var newel,newtext;
for (i=0;i<x.length ;i++)
{
newel=xmlDoc.cr eateElement('ed ition');
newtext=xmlDoc. createTextNode( 'First');
newel.appendChi ld(newtext);
x[i].appendChild(ne wel);
}
var y=xmlDoc.getEle mentsByTagName( "edition")[0].childNodes[0];
document.write( y.nodeValue);
</script>
</body>
</HTML>
xml file: name it as books.xml
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book category="COOKI NG">
<title lang="en">Every day Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILD REN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuer y Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyan athan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learn ing XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
The Result is "First", thats good now go and check ur books.xml file and the new data is not there in.
Thanks.
Nick
I was trying to insert new node and data into the xml file.
Let say If I am inserting the data from page1 at line 4 and displaying the inserted data at line 5, its displaying it perfectly but when I go to the xml file and look for the inserted data its not there. I am I doing any mistake in the code below????
This is the example from w3schools.com
this goes into ur source
<HTML>
<HEAD>
</HEAD>
<body>
<script language="javas cript">
xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.async=fa lse;
xmlDoc.load("bo oks.xml");
var x=xmlDoc.getEle mentsByTagName( 'book');
var newel,newtext;
for (i=0;i<x.length ;i++)
{
newel=xmlDoc.cr eateElement('ed ition');
newtext=xmlDoc. createTextNode( 'First');
newel.appendChi ld(newtext);
x[i].appendChild(ne wel);
}
var y=xmlDoc.getEle mentsByTagName( "edition")[0].childNodes[0];
document.write( y.nodeValue);
</script>
</body>
</HTML>
xml file: name it as books.xml
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book category="COOKI NG">
<title lang="en">Every day Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILD REN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuer y Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyan athan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learn ing XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
The Result is "First", thats good now go and check ur books.xml file and the new data is not there in.
Thanks.
Nick
Comment