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

Cannot load from xml

6 Answers 169 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 13 Apr 2009, 09:49 PM

I have tried mulitple ways to load the treeview and I cannot find one way that works.

 

For instance I have tried using this:

 

RadTreeView1.LoadXml(GetTransformedXmlDoc("TreeViewCombined2.xsl", args)); 

 


Where GetTransformedXmlDoc() returns a correct xml document as a string. All it does is give me XML errors and shows me a node that doesn't even exist in the xml string. This is what it tells me: "There is an error in XML document (1, 40)." When I check for the specific error message this is what I get: "<Nodes xmlns=''> was not expected."

Where that node comes from I have no idea. It's not in the xml I am looking at.



I have tried:
RadTreeView1.DataSource = GetTransformedXmlDoc("TreeViewCombined2.xsl", args);  
RadTreeView1.DataBind(); 

Where GetTransformedXmlDoc()  returns an XmlDataSource object. This sort of worked except I couldn't keep the root node from appearing in the treeview and it also screwed up the text properties of the nodes. Below is a sample xml doc in the exact same form as the one I am trying to load. I cannot set the DataTextField="Text" or the TextField="Text" because my root node doesn't contain that attribute. Is there a way around this?

<Nodes> 
  <TreeViewNode ID="1" Text="Node 1" /> 
  <TreeViewNode ID="2" Text="Node 2" /> 
  <TreeViewNode ID="3" Text="Node 3" /> 
  <TreeViewNode ID="4" Text="Node 4">  
    <TreeViewNode ID="5" Text="Node 5" /> 
  </TreeViewNode> 
  <TreeViewNode ID="6" Text="Node 6" /> 
</Nodes> 


I would appreciate any help as I have wasted the better part of 2 days trying to get this thing to load correctly.

6 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 14 Apr 2009, 08:31 AM
Hello James,

The LoadContentFile method expects the XML to be in a predefined format specific to RadTreeView:

<Tree>
  
<Node Text="North America" Expanded="True" Value="1">
    
<Node>
       
<Node>
       
</Node>
    
</Node>
  
</Node>
</
Tree>

If the the XML format is different the LoadContentFile method would fail.

In your case you should better use the XmlDataSource approach. You need to specify which xml elements are the nodes by setting XPath property of the datasource. In your case you should set the XPath property to "/Nodes/TreeViewNode".

I have attached a sample page which demonstrates the required approach.

I hope this helps,
Albert
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
James
Top achievements
Rank 1
answered on 14 Apr 2009, 07:58 PM
Thanks Albert. I was able to get it working just fine.
0
jfkrueger
Top achievements
Rank 1
answered on 18 Jun 2009, 04:29 PM
XmlDataSource does not exist in WinForms, so what is the solution in a WinForms app?

AND I tried using the XML in your post (and the example)

<
Tree>
  
<Node Text="North America" Expanded="True" Value="1">
    
<Node>
       
<Node>
       
</Node>
    
</Node>
  
</Node>
</
Tree> 

And I still get the error "There is an error in XML document (1, 2)." when trying to load into a treeview.
0
Victor
Telerik team
answered on 19 Jun 2009, 12:56 PM
Hello Joe,

What this means is that your xml file is malformed. I suggest exporting a treeview to xml and examining the generated file. Then all you will need to do is make your file look like the autogenerated one. Write again if you need further assistance.

Kind regards,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
jfkrueger
Top achievements
Rank 1
answered on 19 Jun 2009, 01:07 PM
Hmm, interesting. Especially since I get the exact same error with your XML:

<Tree>
  
<Node Text="North America" Expanded="True" Value="1">
    
<Node>
       
<Node>
       
</Node>
    
</Node>
  
</Node>
</
Tree>

In any case, I ended up just parsing the xml and building the treeview nodes manually.
0
Victor
Telerik team
answered on 19 Jun 2009, 03:15 PM
Hello Joe,

You can also have a look at our XML binding documentation. We are ready to assist you if anything else comes up.

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
James
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
James
Top achievements
Rank 1
jfkrueger
Top achievements
Rank 1
Victor
Telerik team
Share this question
or