Problem with loadXML()

I do exactly as the documentation said, and copy the code from example

xml file loaded from harddisk works fine, however, the one loaded from remote http server has problems.

never get the xml done and show up in the tree component. please help

the codes are as follows :

            tree=new dhtmlXTreeObject(“treeboxbox_tree”,“100%”,“100%”,0);






            tree.attachEvent(“onOpenEnd”,function(nodeId, event){doLog("An id of open item is "+ nodeId);});






            tree.loadXML(“http://localhost:8000/test/default/tree”);//load root level from xml #problem!

            // tree.loadXML(“tree3.xml”); //this line works

I use dhtmlxtree standard version.

I guess it is not necessary to be professional version to have it run ?

It is possible to loaded xml from the same domain as the page with tree (browser’s security).

Please, check that page is loaded from localhost too:


I setup a local webserver for test, localhost:8000/test/default/tree lookss just fine in browser, either IE or Firefox.


the full  html code is attached below:


A demo

html, body {
  font-family: Verdana,sans-serif;
  background-color: #fea;
  color: #000;
a:link, a:visited { color: #00f; }
a:hover { color: #048; }
a:active { color: #f00; }

textarea { background-color: #fff; border: 1px solid 00f; }

<script  src=“codebase/dhtmlxcommon.js”>
<script  src=“codebase/dhtmlxtree.js”>
<script  src=“codebase/dhtmlxtree_start.js”>




<div id=“htmlarea”
 style=“width:1000; height:500;background-color:#f5f5f5;border :1px solid Silver;”



How do you open page that code you have provided ?

Is it opened by localhost:8000/…. in browser ?

this html is called editor.html, which is sent by the web server to the browser.
it is opened by “http://localhost:8000/test/default/editor” in browser, and locally from harddisk in browser as well. either way is okay.

http://localhost:8000/test/default/tree”, which loads tree.xml from the server side, is also okay in browser, but fail in the code.

Please, provide the complete sample with detailed instructions to re-create the issue locally.

in a word, editor.html and tree3.xml are in the same folder.

1. when editor.html is visited locally by double-clicking the file, it successfully loads tree3.xml,
I can see the tree in div, named “treeboxbox_tree”, at left side of the page.

2.when editor.html is visited from http server, it fail to load tree3.xml, nothing appears in “treeboxbox_tree” div.

by the way, today I insert two alert()s as follows:
            tree = new dhtmlXTreeObject(“treeboxbox_tree”,“100%”,“100%”,0);

it is very interesting that,
1. when visiting the editor.html from http server, alert(“1”) showed, whereas alert(2) didn’t show up.
2. when visiting the editor.html locally double-clicking, both alert(“1”) and alert(2) showed.

it seems that the line “tree=new dhtmlXTreeObject(…)” failed so that the program ceased.

Please, provide the complete demo.

i attach the whole demo as .zip to this post, simply it contains just editor.html and a subfolder named “codebase” with the .js files. (128 KB)

Dear Alex , I have solved the problem myself, it is because the web server does not allow directly access such static files as .js or .png under certain folders.
I change the folder, and now it seems okay.

but here raises another question that, as you can see in my code
1 tree = new dhtmlXTreeObject(“treeboxbox_tree”,“100%”,“100%”,0);
2 // tree =  dhtmlXTreeFromHTML(‘htmlarea’); //from html code in the same file

the 2nd line retrieves html/xml code from ‘htmlarea’ div and generate a tree in the same div.
so the question is, is there another way, to retrieve html/xml code from ‘htmlarea’ div and generate a tree in ANOTHER div, ‘treeboxbox_tree’ for instance.
and, keep the ‘htmlarea’ div untouched as it was at the same time?


>> is there another way, to retrieve html/xml code from ‘htmlarea’ div and generate a tree in ANOTHER div, ‘treeboxbox_tree’ for instance.

Tree doesn’t support this feature. You can create to identical containers and one of them can be used for tree initialization.

it is possible to initialize tree in the another container, but in this case we need made a modifications in the dhtmlxtree_start.js (they won’t be supported and included into official version). If you need this modification, let us know and we try to help.

of course we need that thing.
but I think there must be another way, today I saw there is a method named  loadXMLString().
this may load a XML string, and send the string to the tree and the htmlarea div at the same time.

thank you for patient help along the way.

Yes, loadXMLString can be also used. But you should add the root node to the xml string when you use it: