Thread: XML AND JQUERY
View Single Post
  #5 (permalink)  
Old July 9th, 2009, 06:18 AM
pallone pallone is offline
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default XML AND JQUERY

Hi samjudson,

Thank you very much for all your assistance with this issues. It is really appreciated.

Sorry for not listing what I was expecting and for not being more clear.

I have seen your new sample code and it works fine if the name element has no attributes or other children since the code hard code the name element. However, for a more complex structure it would not work.

Is it possible to adjust the code around to instead of hard coding the name of the element, we would get it dynamically and include its attributes and child nodes?

For example, the address element of the xml looks like this:

<address id="1">
<street>45 Usura Place</street>
<city>Hailey</city>
<province>ID</province>
</address>

How do I grab all the address elements from the xml with all its attributes and child nodes and append it to a new xml document with a <Locations> root element?

<Locations>
<address id="1">
<street>45 Usura Place</street>
<city>Hailey</city>
<province>ID</province>
</address>
<address id="2">
<street>3 Prufrock Lane</street>
<city>Stamford</city>
<province>CT</province>
</address>
<address id="3">
<street>10 Bridge Tunnel</street>
<city>Harlem</city>
<province>NY</province>
</address>
</Locations>

Thanks again


XML
-------

<?xml version="1.0" encoding="utf-8"?>
<labels>
<label id='ep' added="2003-06-10">
<name>Ezra Pound</name>
<address id="1">
<street>45 Usura Place</street>
<city>Hailey</city>
<province>ID</province>
</address>
</label>
<label id='tse' added="2003-06-20">
<name>Thomas Eliot</name>
<address id="2">
<street>3 Prufrock Lane</street>
<city>Stamford</city>
<province>CT</province>
</address>
</label>
<label id="lh" added="2004-11-01">
<name>Langston Hughes</name>
<address id="3">
<street>10 Bridge Tunnel</street>
<city>Harlem</city>
<province>NY</province>
</address>
</label>
</labels>
Reply With Quote