Thread: XML AND JQUERY
View Single Post
  #1 (permalink)  
Old July 8th, 2009, 12:48 PM
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,

I would appreciate very much if someone could shed some light on how to retrieve a nodeset from an xml document - not the value - and then append the elements within the nodeset to a new xml tree with JQUERY.

By the way, is it possible to create an empty xml document using JQUERY???

I have tried the code below but it is not working as expected. I am not sure how to loop to get all nodes from the set.

$(document).ready(function() {
//debugger
$.get("labels.xml", function(xml) {
//var text = $("name", xml).text();
var text = $("name", xml);
alert(text[0].xml)
//debugger
$("div#xml").html("<Names>" + text[0].xml + "</Names>");
});
});

This is what I get from this code and as you can see, the xml is not well formed.
<DIV id="xml">
<NAMES></NAMES><NAME></NAME>Claudio Pallone</NAME><//NAME></NAMES><//NAMES>
</DIV>

XML USED

<?xml version="1.0" encoding="utf-8"?>
<labels>
<label id='ep' added="2003-06-10">
<name>Ezra Pound</name>
<address>
<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>
<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>
<street>10 Bridge Tunnel</street>
<city>Harlem</city>
<province>NY</province>
</address>
</label>
</labels>


Cheers

C
Reply With Quote