Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 7th, 2004, 03:52 PM
Registered User
 
Join Date: Oct 2004
Location: cincinnati, ohio, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to willgotoo
Default javascript - add element to existing xml?

Hi. New to xml and this forum.. have the Beginning XML book and have been trying to figure out the DOM. I can create a new xml object and use the append child to add an element.

Is there a way to load an existing XML file and then insert an element to it?

for example...

Load an XML from a file...

<custorders>
   <order id="001"/>
</custorders>

submit a form and change the XML file

<custorders>
   <order id="001"/>
   <order id="002"/>
</custorders>

This file would be local on the client C: drive.

Thanks for any help.
  #2 (permalink)  
Old October 7th, 2004, 04:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Sure, you would create a new element of type order, add the attribute, and then append it to the root. Haven't done it in JavaScript so I can't help you further.

Sorry about that,

Brian
  #3 (permalink)  
Old October 7th, 2004, 05:24 PM
Registered User
 
Join Date: Oct 2004
Location: cincinnati, ohio, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to willgotoo
Default

Brian,

That is what I've been trying to do. If I create a new DOM object, I can append to it. But if I create the DOM object and then load an existing XML into it, the appendChild method doesn't work.

I've been using the example directly from the Wrox Beginning XML book...but that example is done an a new XML object, and not one that has been loaded from an existing file.

  #4 (permalink)  
Old October 8th, 2004, 02:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

The appendChild method works regardless of whether the DOM is newly created or loaded from a file. I don't have the book, so show us the code that doesn't work.
  #5 (permalink)  
Old October 8th, 2004, 09:33 AM
Registered User
 
Join Date: Oct 2004
Location: cincinnati, ohio, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to willgotoo
Default

Pgtips and Brian,
Thanks for the quick help...although the book seemed to indicate that the append worked with a loaded file, the example didn't show that so I wasn't 100% sure.
Anyway, with your help I figured out my problem. With a new object, the appendedChild method was creating the root element. With the loaded file, I needed to create a node object that held the parentnode <custorders>, and then I was able to append the <order> element to the the parent.
Thanks!


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically add a new row to a existing GridView srkvellanki ASP.NET 2.0 Professional 1 September 21st, 2008 09:15 PM
VB.net, adding XML data to an existing XML file saikoboarder XML 11 April 17th, 2008 04:19 PM
Add a new record between two existing records hsncompany BOOK: Beginning Access 2003 VBA 0 April 13th, 2008 03:36 PM
How to add fields to an existing table using VBA donrafeal Access VBA 3 March 22nd, 2006 06:11 PM
Add an attribute to existing table peter_budo SQL Language 9 April 24th, 2005 01:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.