Jstree doesn't build a tree

I am trying to build a tree from an xml file using jstree. I followed the documentation and looked as if it didn't work. Here is my code:

<html>
<head>
    <title>Demo</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="C:\Users\jstree\jstree_pre1.0_fix_1\jquery.jstree.js"></script>
    <Script Language="JavaScript">
  $(function () {  

     $("#demo2").jstree({   

         "xml_data" : {  

             "ajax" : {  

                 "url" : "books.xml" 

             },  

             "xsl" : "nest" 

         },  

         "plugins" : [ "themes", "xml_data" ]  

     });  
     }); 

</Script>

</head>
<body>

</body>

+3
source share
4 answers

XML is not formatted in such a way that jsTree can include it.

http://www.jstree.com/documentation/xml_data

Two types of XML structures are supported: flat and nested:

<!-- FLAT -->
<root>
    <item id="root_1" parent_id="0" state="closed">
        <content>
            <name><![CDATA[Node 1]]></name>
        </content>
    </item>
    <item id="node_2" parent_id="root_1">
        <content>
            <name><![CDATA[Node 2]]></name>
        </content>
    </item>
</root>

<!-- NESTED -->
<root>
    <item id="xml_1">
        <content><name><![CDATA[Root node 1]]></name></content>
        <item id="xml_2">
            <content><name><![CDATA[Child node 1]]></name></content>
        </item>
    </item>
</root>

An alternative is to transfer the XML document and convert it to JSON, and then convert it to a valid JSON or HTML data format.

+2
source

It looks like the container (# demo2) is missing. Try adding <div id='demo2'></div>under the body tag.

Also ensure that the jstree.js file loads correctly.

+1
source

script, "" (, , ).

script, ,

<script type="text/javascript">
    //Your Code Here
</script>
0

"url": "books.xml" . , "url": "../Content/Xml/books.xml" . .

Regards, Amrutha

0
source

All Articles