views:

15

answers:

2

Using E4X, i can easily access nodes in XML using javascript as follows:

<script language="javascript">
xmldata = <books><book><title>AA</title></book></books>; // notice the no string quotes

alert(xmldata.book.title); 
</script>

However, the application returning the data to me is returning XML as string. How can i access using this :

<script language="javascript">
xmldata = '<books><book><title>AA</title></book></books>'; // string quote around the xmldata

alert(xmldata.book.title); 
</script>

This would give me a javascript error. Can someone please tell me how i can achieve the earlier result ?

A: 

The XML constructor defined in E4X accepts an XML string as an argument. So for your second example, try

var xmldata = '<books><book><title>AA</title></book></books>';
var xml = new XML(xmldata); // takes in an xml string

alert(xml.book.title);
Anurag
A: 

Works like a charm. However, there is another problem. How do i get this to work ?

xmldata ='<?xml version="1.0" encoding="UTF-8"?><books><book><title>AA</title></book></books>';
xml = new XML(xmldata);

alert(xml.book.title);
WarDoGG
see this bug - https://bugzilla.mozilla.org/show_bug.cgi?id=336551
Anurag