dhtmlxtree

Hi, team!

My question is: how can I load xmlDoc which one is not in some file

example:

var tree=new dhtmlXTreeObject(‘content_newsgrid’,“100%”,“100%”,0);            tree.setImagePath(“…/lib/dhtmlxtree/codebase/imgs/csh_bluefolders/”);



var xmlDoc;

    if ( document.implementation && document.implementation.createDocument ) {

        try {

            xmlDoc = document.implementation.createDocument(‘’, ‘’, null);

        } catch (e) {}

    }

    if ( !xmlDoc ) {

        xmlDoc = document.createElement(‘xml’);

    }

    var rows = xmlDoc.createElement(‘tree’);

    for ( var i = 0; i < 3; ++i ) {

            var row = xmlDoc.createElement(‘item’);

            row.setAttribute(‘id’, ‘ss’+i);

            row.setAttribute(‘text’, ‘ss’+i);                

            rows.appendChild(row);

    }



please help me

thank you!

    xmlDoc.appendChild(rows);

Do you have some specific use-case, where you need to construct XML document on client side?
You can use slightly different approach.

var xml="";
xml+="";
for ( var i = 0; i < 3; ++i )
xml="";
xml+="";

tree.loadXMLString(xml);

Thank you
I have already  tried this method, it works good, but i have a problem with some character at several nodes and I have an error “Incorrect XML” (I use encoding=“windows-1251”)

there is one more approach : use your tree method “insertNewChild”



When using loadXMLString in IE , document always treated as UTF encoded ( limitation of browser ) , so it really can cause issues with windows-1251 encoding.
As one more solution - loading from JSON can be used ( dhtmlxtree_json.js )
var data={id:0,item:[]};
for ( var i = 0; i < 3; ++i )
data.item.push({ id:“ss”+i, text:“ss”+1});
tree.loadJSONObject(data);

JSON data using the same encoding as the page uses, so it must not cause problems with windows-1251 encoded data.