Parsing XML Data, not from a node

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Parsing XML Data, not from a node

Fabian Dittrich
Hi everybody,

i can parse a node in DOJO like this:

var testObjects = new dojo.xml.Parse();
testItems = testObjects.parseElement(document.getElementById("test"));
where the "test" node is a part of my html, but what if i just a a variable containing some xml. Let´s say i get some XML from the server and i dont want to do the workaround to first create a dom node from it and then parse it, i want to directly parse it.

Example:

var some_javascript_var = "<xmltest>test_value</xmltest>";

in this case parsing this xml does not work like this:

var testObjects = new dojo.xml.Parse();
testItems = testObjects.parseElement(some_javascript_var);

How DOES it work?

Thanks in advance

Fabian


_______________________________________________
Dojo-interest mailing list
[hidden email]
http://dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Parsing XML Data, not from a node

Alex Russell
On Thursday 15 December 2005 4:19 pm, Fabian Dittrich wrote:

> Hi everybody,
>
> i can parse a node in DOJO like this:
>
> var testObjects = new dojo.xml.Parse();
> testItems =
> testObjects.parseElement(document.getElementById("test"));
>
> where the "test" node is a part of my html, but what if i just a a
> variable containing some xml. Let´s say i get some XML from the
> server and i dont want to do the workaround to first create a dom
> node from it and then parse it, i want to directly parse it.
>
> Example:
>
> var some_javascript_var = "<xmltest>test_value</xmltest>";
>
> in this case parsing this xml does not work like this:
>
> var testObjects = new dojo.xml.Parse();

So in this case, you're passing in a string and not a DOM node, which is
what the Dojo first-pass parser expects. To create a document out of
this string, use dojo.dom.createDocumentFromText(), like this:
       
        var some_javascript_var = "<xmltest>test_value</xmltest>";
        var testDoc = dojo.dom.createDocumentFromText(some_javascript_var);
        var testObjects = new dojo.xml.Parse();
        // might need to pass testDoc.documentElement or similar
        var testItems = testObjects.parseElement(testDoc);

It would be good if the parser tried to do this for you. Perhaps a bug
should be filed to this effect?

Regards

--
Alex Russell
[hidden email] BE03 E88D EABB 2116 CC49 8259 CF78 E242 59C3 9723
[hidden email]  F687 1964 1EF6 453E 9BD0 5148 A15D 1D43 AB92 9A46
_______________________________________________
Dojo-interest mailing list
[hidden email]
http://dojotoolkit.org/mailman/listinfo/dojo-interest
Loading...