473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with updating the XML file

NawazAhmed
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="javascript">
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("books.xml");
var x=xmlDoc.getElementsByTagName('book');
var newel,newtext;
for (i=0;i<x.length;i++)
{
newel=xmlDoc.createElement('edition');
newtext=xmlDoc.createTextNode('First');
newel.appendChild(newtext);
x[i].appendChild(newel);
}
var y=xmlDoc.getElementsByTagName("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="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<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">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning 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
Mar 3 '08 #1
3 3000
jkmyoung
2,057 Expert 2GB
You're misinterpreting the intentions of this script.
The intention is to grab data dynamically from an xml file which may be changing, and display the most recent information. This is not a script to update a file.

Further, you can't really save to disk with javascript most of the time, due to security permissions.

If you want the result, you need a browser which will allow you to save the processed result.

You need to find another way to do this. I suggest PHP.
Mar 3 '08 #2
If this is not the code then can u send me the correct one please.
Since I saw this example on w3schools website so I was trying to do this.

Thanks.

You're misinterpreting the intentions of this script.
The intention is to grab data dynamically from an xml file which may be changing, and display the most recent information. This is not a script to update a file.

Further, you can't really save to disk with javascript most of the time, due to security permissions.

If you want the result, you need a browser which will allow you to save the processed result.

You need to find another way to do this. I suggest PHP.
Mar 3 '08 #3
The best way to update XML documents is using VTD-XML
http://vtd-xml.sf.net

See this article: http://www.javaworld.com/javaworld/jw-07-2006/jw-0724-vtdxml.html


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="javascript">
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("books.xml");
var x=xmlDoc.getElementsByTagName('book');
var newel,newtext;
for (i=0;i<x.length;i++)
{
newel=xmlDoc.createElement('edition');
newtext=xmlDoc.createTextNode('First');
newel.appendChild(newtext);
x[i].appendChild(newel);
}
var y=xmlDoc.getElementsByTagName("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="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<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">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning 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
Mar 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the...
4
by: Wes | last post by:
Hello, I have an application using an xml dataset to store app and user settings. The problem I am having is related to writexml. I have a save button on my application that updates the dataset...
1
by: Zeng | last post by:
Hello, I don't know why I'm the only one in my development team get this build error when I build the entire solution. CommonLib.dll is a binary file resulted of building another project...
1
by: Doug Lim | last post by:
I have an ASP.NET application that I've developed using Visual Studio ..NET 2003 and I'm making use of Crystal Reports for .NET that's included to return reports back to the visitor's web browser...
14
by: Nick Gilbert | last post by:
Hi, I have an asp.net application which runs from a CD-ROM using Cassini. As such, it is single user only. The application connects to an Access database when it is loaded, and keeps the same...
6
by: muttu2244 | last post by:
hi all am updating the same file in ftp, through multiple clients, but am scared that two clients may open the same file at a time, and try updating, then the data updated by one data will be...
3
by: slinky | last post by:
I have an aspx for with a textbox and a button. The goal is to simply have the user type a message, hit the button and it should append to the XML file. I can open the aspx in the browser with no...
3
by: Evan | last post by:
Hello - My script use a DB file which is written by XML, and the user load this DB file (XML tree in memory), and then do some updating about this tree, such as delete element, generate new...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
1
by: Christoph Boget | last post by:
I'm experiencing a very odd problem and it's happening only in IE6. IE7, Safari, Opera and Firefox are all working properly. What's happening is that I'm using XHR request responses to update the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.