This is a migrated thread and some comments may be shown as answers.

Tree View and XML Data Source

3 Answers 265 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Thanos
Top achievements
Rank 1
Thanos asked on 05 Nov 2012, 11:07 AM
Hello,
I've been reading the existing documentation about the Treeview as well as the Hierarchical Data Source and the Data Source but I kinda lost it about the possible remote data source types that I can use with the Treeview.
Apart from json,xml is also supported right?Is it possible to bind it and view the xml file with the Treeview?
I've been trying something like:

<title>Tree View</title>
     
<link href="shared/styles/examples-offline.css" rel="stylesheet">
<link href="styles/kendo.common.min.css" rel="stylesheet">
<link href="styles/kendo.blueopal.min.css" rel="stylesheet">
 
<script src="js/jquery.min.js"></script>
<script src="js/kendo.web.min.js"></script>
<script src="shared/js/console.js"></script>
 
</head>
<body>
        <div id="example" class="k-content">
        <div id="treeview" class="demo-section"></div>
 
            <script>
                var ds = new kendo.data.DataSource({
                        transport: {
                            read: {
                                url:"http://localhost:8080/OnTheSpotRestfullAPI/testTree.xml"
                            }
                        },
                        schema: {
                            type: "xml",
                            data: "/tree/vehicles",
                            model: {
                                fields: {
                                    car: "car/text()",
                                    bike: "bike/text()"
                                }
                            }
                        }
                    });
 
                $("#treeview").kendoTreeView({
                    dataSource: ds
                });
            </script>
 
            <style scoped>
                #example {
                    text-align: center;
                }
 
                .demo-section {
                    display: inline-block;
                    vertical-align: top;
                    width: 320px;
                    height: 300px;
                    text-align: left;
                    margin: 0 2em;
                }
            </style>
        </div>
 
 
</body>
</html>

with the testTree.xml being:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tree>
    <vehicles>
        <car>FM-1100</car>
        <car>FM-4200</car>
        <bike>FM-3100</bike>
    </vehicles>
    <personnel>
        <client>GH-3000</client>
        <vip>GH-3100</vip>
    </personnel>
</tree>

but I can't seem to be able to view the tree at all..kinda lost here,can someone please point me to the right direction?

Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Hari
Top achievements
Rank 1
answered on 07 Dec 2012, 10:40 AM
Hi,
Were you able to resolve your issue? We wanted to do that same thing and struck. Can you help us?
0
Thanos
Top achievements
Rank 1
answered on 07 Dec 2012, 08:21 PM
Hey,
I posted here and I found some help,but it wasn't supported much as a dataSource type so I used JSON in the end and got the results I wanted.
0
Hari
Top achievements
Rank 1
answered on 10 Dec 2012, 04:59 PM

I am trying to convert my sample XML file as JSON object and set that as a datasource to my tree view control. Its not working. I am sure that I am missing something here but not sure what's that. Please help me.


Here is my code in Controller class where I am loading the XML file and retruning as JSON


        public JsonResult Employees()
       
{

           
XElement xdoc = XElement.Load("C:\\Users\\a409114\\Desktop\\TreeView.xml");
           
return Json(xdoc, JsonRequestBehavior.AllowGet);
       
}

Here is my code in the view file where I am invoking the action name "Employees" in my controller class "TreeViewController".


<div class="demo-section">
@(Html.Kendo().TreeView()
   
.Name("treeview")
    
.DataTextField("vehicles")
   
.DataSource(dataSource => dataSource
       
.Read(read => read
           
.Action("Employees", "TreeView")
       
)
   
)
)
</div>

<style scoped>
.demo-section {
    width
: 200px;
}
</style>

Here is my sameple XML file:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tree>
<vehicles>
   
<car>FM-1100</car>
   
<car>FM-4200</car>
   
<bike>FM-3100</bike>
</vehicles>
<personnel>
   
<client>GH-3000</client>
   
<vip>GH-3100</vip>
</personnel>
</tree>

This is not loding the Tree View Control!

Can you please help me?
Tags
TreeView
Asked by
Thanos
Top achievements
Rank 1
Answers by
Hari
Top achievements
Rank 1
Thanos
Top achievements
Rank 1
Share this question
or