Reading XML issue
Reading XML issue
Hi, I am facing problem while reading following XML data:
XML DATA (saved in test.xml):
<sites>
<site id="0">
<url loc="http://www.abc.com" /> //Error
<title>ABC</title>
<desc>
<brief>this is the brief description.</brief>
<long>...and this is the long description. See how long it is :)</long>
</desc>
</site>
</sites>
JQuery CODE:
$.ajax({
type: "GET",
url: "test.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('site').each(function(){
var id = $(this).attr('id'); //#1
var url = $(this).find('url').text(); //#2
var title = $(this).find('title').text();
$(this).find('desc').each(function(){
var brief = $(this).find('brief').text();
var long = $(this).find('long').text();
});
}
});
Using above jQuery, could not read XML data after line no marked as #1.
However if I change the XML data as follows then it reads data correctly.
In XML data line marked as //Error:
Old: <url loc="http://www.abc.com" />
replaced as
New: <url loc="http://www.abc.com"></url>
Is there any way to read XML data having data as <XmlTag /> instead of using <XmlTag></XmlTag>.
Please guide.