New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Loading XML Content

You can load an XML content file to define your Tree. The XML file should be structured so that the root Node is named "Tree". Under that any number of <Node> tags can be nested. Within each Node, define attributes that map to RadTreeNode properties. For example:

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

Loading from an XML file

Create an XML file with content that complies with the rules described above and call the LoadContentFile() method to load the Nodes, passing in the path to the file:

RadTreeView Binding to XML

  <Node Text="North America" Expanded="True" Value="1">
      <Node Text="U.S.A." Expanded="True">
          <Node Text="New York" Value="2" />
          <Node Text="Los Angeles" />
          <Node Text="Boston" />
          <Node Text="Chicago" />
      <Node Text="Canada">
          <Node Text="Toronto" />
          <Node Text="Vancouver" />
          <Node Text="Calgary" />
          <Node Text="Ottawa" />
      <Node Text="Mexico">
          <Node Text="Campeche" />
          <Node Text="Guadalajara" />
          <Node Text="Mexico City" />
          <Node Text="Puebla" />
  <Node Text="Europe">
      <Node Text="England">
          <Node Text="London" />
          <Node Text="Liverpool" />
          <Node Text="Leeds" />
          <Node Text="Manchester" />
      <Node Text="France">
          <Node Text="Paris" />
          <Node Text="Cannes" />
          <Node Text="Grenoble" />
          <Node Text="Toulouse" />
      <Node Text="Germany">
          <Node Text="Berlin" />
          <Node Text="Bonn" />
          <Node Text="Bremen" />
          <Node Text="Munich" />
  <Node Text="South America">
      <Node Text="Brasil">
          <Node Text="Rio de Janeiro " />
          <Node Text="Sao Paulo" />
          <Node Text="Campinas" />
          <Node Text="Brasilia" />
      <Node Text="Argentina">
          <Node Text="Buenos Aires " />
          <Node Text="Cordoba" />
      <Node Text="Chile">
          <Node Text="Arica" />
          <Node Text="Copiapo" />
          <Node Text="Puerto Montt" />
  <Node Text="Africa">
      <Node Text="South Africa">
          <Node Text="Cape Town" />
          <Node Text="Johannesburg" />
          <Node Text="Pretoria " />
      <Node Text="Zambia">
          <Node Text="Lusaka" />
      <Node Text="Zimbabwe">
          <Node Text="Harare" />

A button click event handler calls the LoadContentFile() method:

protected void Button1_Click(object sender, EventArgs e)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Loading from an XML string

Create a string with valid XML content (or fetch it from a database, for example) and use the LoadXML() method to populate the TreeView from the string:

StringBuilder sb = new StringBuilder();
sb.Append(" <Node Text='Root Node 1'>");
sb.Append(" </Node>");
sb.Append(" <Node Text='Root Node 2'>");
sb.Append(" </Node>");
sb.Append(" <Node Text='Root Node 3'>");
sb.Append(" <Node Text='Child Node'>");
sb.Append(" </Node>");
sb.Append(" </Node>");
sb.Append(" </Tree>");
string xmlString = sb.ToString();
Dim sb As New StringBuilder()
sb.Append(" <Node Text='Root Node 1'>")
sb.Append(" </Node>")
sb.Append(" <Node Text='Root Node 2'>")
sb.Append(" </Node>")
sb.Append(" <Node Text='Root Node 3'>")
sb.Append(" <Node Text='Child Node'>")
sb.Append(" </Node>")
sb.Append(" </Node>")
sb.Append(" </Tree>")
Dim xmlString As String = sb.ToString()

For a live example of loading RadTreeView Nodes from XML, see Populating from XML.

In this article