Loading multiple trees from same XML on multiple pages

5 posts, 1 answers
  1. Jerry
    Jerry avatar
    49 posts
    Member since:
    Mar 2012

    Posted 25 Sep 2020 Link to this post

    Hello,

    We are working on multiple document pages, that we want to have the same XML source file to populate both pages but with different data from the XML file.

    For example if we had a baseball.XML file that listed all the teams in MLB and we have a page for American league and a separate page for Nation league.

    We want both pages to get the data from the same XML file and populate multiple treeviews.  We also want to break it down by division.  We want the name of the team to be a link to the team homepage.

    This is an example of one of the pages:

    American League

    -AL East

      -Tampa Bay

      -New York

    +AL Central

    +AL West

     

    Is this possible with XML and treeview control?  Thank you for any help or direction you can give me. 

  2. Attila Antal
    Admin
    Attila Antal avatar
    609 posts

    Posted 30 Sep 2020 Link to this post

    Hi Jerry,

    Controls can bind to data provided the data source, so if you have an XML file that has a large set of data that can be split into multiple parts, you will need to turn them into data sources and bind them to different controls. Since Web UI components do not do that unless they are created specifically for that reason, you will need to use other means to split the XML data into multiple chunks and convert them to data sources, and finally, bind them to individual controls. You can use the .NET Framework to read the XML content split the data into as many parts you need, and turn those into data sources.

    Here is one article that may be helpful for your case: Loading a DataSet from XML.

    Regards,
    Attila Antal
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. Jerry
    Jerry avatar
    49 posts
    Member since:
    Mar 2012

    Posted 08 Oct 2020 in reply to Attila Antal Link to this post

    Attila Antal said:

    Hi Jerry,

    Controls can bind to data provided the data source, so if you have an XML file that has a large set of data that can be split into multiple parts, you will need to turn them into data sources and bind them to different controls. Since Web UI components do not do that unless they are created specifically for that reason, you will need to use other means to split the XML data into multiple chunks and convert them to data sources, and finally, bind them to individual controls. You can use the .NET Framework to read the XML content split the data into as many parts you need, and turn those into data sources.

    Here is one article that may be helpful for your case: Loading a DataSet from XML.

    Regards,
    Attila Antal
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

     

    Thank you Attila,

    Here is an example of the XML I'm using. Currently if I put this into a dataset the tree displays all nodes at the same level.  It doesn't nest the nodes.  I'm going to split section 1 and 2 and use 2 different radTreeViews, but I have to get them to nest first.

    <Tree>
      <Node Text="Section 1" Expanded="True" ID="1">
        <Node Text="Sub-Section 1" Expanded="True" ID="10">
          <Node Text="Documents">
            <Node Text="2020">
              <Node Text="Doc 1" NavigateUrl="http://www.temp.com/doc1.pdf" target="_blank" />
              <Node Text="Doc 2" NavigateUrl="http://www.temp.com/doc2.pdf" target="_blank" />
              <Node Text="Doc 3" NavigateUrl="http://www.temp.com/doc3.pdf" target="_blank" />
            </Node>
          </Node>
        </Node>
        <Node Text="Sub-Section 2" Expanded="True" ID="11">
          <Node Text="Documents">
            <Node Text="2020">
              <Node Text="Doc 4" NavigateUrl="http://www.temp.com/doc4.pdf" target="_blank" />
              <Node Text="Doc 5" NavigateUrl="http://www.temp.com/doc5.pdf" target="_blank" />
              <Node Text="Doc 6" NavigateUrl="http://www.temp.com/doc6.pdf" target="_blank" />
            </Node>
          </Node>
        </Node>
      </Node>
      <Node Text="Section 2" Expanded="True" ID="2">
        <Node Text="Sub-Section 1" Expanded="True" ID="20">
            <Node Text="Documents">
              <Node Text="2020">
                <Node Text="Doc 10" NavigateUrl="http://www.temp.com/doc10.pdf" target="_blank" />
                <Node Text="Doc 20" NavigateUrl="http://www.temp.com/doc20.pdf" target="_blank" />
                <Node Text="Doc 30" NavigateUrl="http://www.temp.com/doc30.pdf" target="_blank" />
              </Node>
            </Node>
          </Node>
          <Node Text="Sub-Section 2" Expanded="True" ID="21">
            <Node Text="Documents">
              <Node Text="2020">
                <Node Text="Doc 40" NavigateUrl="http://www.temp.com/doc40.pdf" target="_blank" />
                <Node Text="Doc 50" NavigateUrl="http://www.temp.com/doc50.pdf" target="_blank" />
                <Node Text="Doc 60" NavigateUrl="http://www.temp.com/doc60.pdf" target="_blank" />
              </Node>
            </Node>
        </Node>
      </Node>
    </Tree>

    Here is my C# code to load the dataset into my radTreeView

    DataSet ds = new DataSet();
    ds.ReadXml(Server.MapPath("~/Temp.xml"));
    radtreeCol1.DataTextField = "Text";
    radtreeCol1.DataSource = ds;
    radtreeCol1.DataBind();

     

    Thank you for any help you can give me. 

     

     

     

     

  4. Answer
    Attila Antal
    Admin
    Attila Antal avatar
    609 posts

    Posted 12 Oct 2020 Link to this post

    Hi Jerry,

    That is good news. Seems that the data binding kicked in and it started working. The reason the items are all displayed on the same level is the missing Relation between the items. Records in the DataSource must have a field that you can use to relate the items. For example, DataFieldParentID pointing to the ID of an item. This item will then render as a child of that item.

    See the explanation in Binding to Array and ArrayList and  Binding to a Database articles.

    Regards,
    Attila Antal
    Progress Telerik

    Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

  5. Jerry
    Jerry avatar
    49 posts
    Member since:
    Mar 2012

    Posted 12 Oct 2020 in reply to Attila Antal Link to this post

    Thank you Attila,

     

    This helped a lot.

Back to Top