Cannot load from xml

7 posts, 1 answers
  1. James
    James avatar
    5 posts
    Member since:
    Apr 2009

    Posted 13 Apr 2009 Link to this post

    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.
  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 14 Apr 2009 Link to this post

    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.
  3. James
    James avatar
    5 posts
    Member since:
    Apr 2009

    Posted 14 Apr 2009 Link to this post

    Thanks Albert. I was able to get it working just fine.
  4. jfkrueger
    jfkrueger avatar
    269 posts
    Member since:
    Jul 2012

    Posted 18 Jun 2009 Link to this post

    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.
  5. Victor
    Admin
    Victor avatar
    1358 posts

    Posted 19 Jun 2009 Link to this post

    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.
  6. jfkrueger
    jfkrueger avatar
    269 posts
    Member since:
    Jul 2012

    Posted 19 Jun 2009 Link to this post

    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.
  7. Victor
    Admin
    Victor avatar
    1358 posts

    Posted 19 Jun 2009 Link to this post

    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.
Back to Top