Binding Complex XML to TreeView

2 posts, 0 answers
  1. Prakash
    Prakash avatar
    19 posts
    Member since:
    Oct 2010

    Posted 04 Jan 2012 Link to this post

    Hi,

    Telerik Version: 2010.2.924.1040

    Requirement: 

    I've a following XML and I want to bind that to RadTreeView, Please help me in doing this task. 

    I've seen the following link and found that XML nodes are of same type, XmlNodeItem, Items
    Whereas I need an example where the XML has different type of nodes at each level.

    http://www.telerik.com/help/silverlight/radtreeview-populating-with-data-data-binding-to-xml.html

    The following is sample XML, which is very close to my actual XML. I'm waiting for your response at the earliest. 

    <Channels>
           <Channel>
    <Name>STAR</Name>
    <Programmes>
                          <Program>
    <ProgramName>News</ProgramName>
    <ProgramID>Star001</ProgramID>
    <Duration>30M</Duration>
    <Advertisements>
                                                <Advertisement>
    <AdvertisementName>Advertisement 1</Advertisement>
     <Advertisement>
    <Advertisement>
                                                      <AdvertisementName>Advertisement 2</Advertisement>
                                                </Advertisement>
     </Advertisements>
    </Program>
                        <Program>
                                   <ProgramName>Movie</ProgramName>
                                   <ProgramID>Start002</ProgramID>
                                   <Duration>3H</Duration>
                                   <Advertisements>
    <Advertisement>
    <AdvertisementName>Advertisement 1</AdvertisementName>
    </Advertisement>
    </Advertisements>
                        </Program>
    </Programmes>
          </Channel>
           <Channel>
    .
    .
    .
    </Channel>
    </Channels>

    Thanks,
    Prakash.
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 09 Jan 2012 Link to this post

    Hi Prakash,

    Basically in order to display multiple child types in the RadTreeViewItems hierarchy, you need to make sure that they inherit one common type. Please note that you can only set one children collection as an ItemsSource in an HierarchicalDataTemplate for each RadTreeViewItem and this is why you need to define only one children collection for each item and populate it with all children items even if they are different.

    Please have a look at this forum thread where a similar scenario is described. The approach that is demonstrated there can be used along with the approach for displaying XML data in the RadTreeView (from the help article). Please give it a try and let me know if it helps.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
Back to Top