Load XML directly (not as string)

Hello,



I have some data in XML representation that I would like to load into DHTMLX Tree. Unfortunately, DHTMLX Tree can only load XML in string representation. Hence, I convert the XML to a string like this:



var xmlString = (new XMLSerializer()).serializeToString(xmlData);



This is slow, but works perfectly in Firefox. However, it does not work in IE (latest version).



Is there any way to pass the XML directly to DHTMLX Tree, without having to convert it to a string first?



Thank you!



Steffen

there is no native API, but can be done in next way

if your object is instance of XMLHTTPRequest you can init tree as

var temp=new dtmlXMLLoaderObject();
temp.xmlDoc=xml_obj;
tree._parseXMLTree(tree,null,null,null,null,temp);

If its just an XML document ( only starting from dhtmlxtree 1.6 )

var top= <<top node of xml, fetched from your object>>;
var pointer=new xmlPointer(top);
tree._parse(pointer)
tree._p=pointer;


Also, just for info , it possible to serialize data to string in IE as well
    var xmlString = xmlData.documentElement.xml;

Hello,

Thanks for your quick reply - I greatly appreciate it.

I am about to try the second solution you proposed, but don’t know how to find the top node:

var top = <<top node of xml, fetched from your object>>;

I tried

var top = $(data).find(“tree”);

using jQuery, but that didn’t work.  I use the regular XML syntax, starting with .

Thanks in advance,

Steffen

Actually,

var top = data.documentElement;

did the trick.  Is this the correct way of finding the top node?

Thanks,

Steffen

did the trick.  Is this the correct way of finding the top node?
This is definitely correct for IE, not sure that it correct for all versions of FF

You can use
    xml.getElementsByTagName(“tree”)[0]