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

Element vs. Attribute

5 Answers 47 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 15 Dec 2012, 01:51 AM
I can get the tree list working fine when I use attribute based xml.
<catalog>
<catalogitem id="1" name="test 1"/>
<catalogitem id="2" name="test 2"/>
</catalog>

but the xml I'm getting from a web service is doing this:
<catalog>
    <catalogitem>
        <id>1</id>
        <name>test 1</name>
    <catalogitem>
    <catalogitem>
        <id>2</id>
        <name>test 2</name>
    <catalogitem>
</catalog>

I have no problem binding the RadGrid to the xml like the latter but I can't seem to figure out how to do it for a treelist.

Also, is there any way to start the parent id as 0 instead of null/empty??

5 Answers, 1 is accepted

Sort by
0
Kyle
Top achievements
Rank 1
answered on 19 Dec 2012, 02:28 AM
I'm still stuck. Any ideas? I really don't want to convert the xml that I receive.
0
Antonio Stoilkov
Telerik team
answered on 19 Dec 2012, 11:05 AM
Hi Kyle,

In order to resolve your issue you could specify the classes that are returned from the web service the correct attributes as shown in the example below. Note that the default attribute value is XmlElement.
public class CatalogItem
{
    [XmlAttribute]
    public int Id { get; set; }
    [XmlAttribute]
    public string Name { get; set; }
}

Could you please provide more information of what you mean by starting the parent id as 0 instead of null\empty?

All the best,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Kyle
Top achievements
Rank 1
answered on 19 Dec 2012, 08:29 PM
I'm not sure that's going to work for me. My elements are unknown at design time. Once I see the xml I would like to display the tree. I was creating the columns dynamically at runtime.

As for the parentid. My xml is using a guid as the id and parentid fields. The parentid of the top most element in the tree is an empty guid or 00000000-0000-0000-0000-000000000000 but not null or empty string.
0
Antonio Stoilkov
Telerik team
answered on 21 Dec 2012, 07:02 AM
Hello Kyle,

Another possible option to alter the XML document is to use transformation files as described below.

Additionally, you could go through the help article below for more information about how it constructs its items.

Note that you could resolve both of your issue by manually parsing the data in custom objects which instead of empty Guid contain null values and the TreeList could be easily data bound to this data.

All the best,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Kyle
Top achievements
Rank 1
answered on 02 Jan 2013, 04:50 AM
I think I found a good way to do it.

 

XmlDocument response = request.Send();

 

XmlReader xmlReader = new XmlNodeReader(response.SelectSingleNode("response/content/readbyquery/collection"));

dsCatalog.ReadXml(xmlReader);

RadGrid1.DataSource = dsCatalog;

This seemed to work well.

Tags
TreeList
Asked by
Kyle
Top achievements
Rank 1
Answers by
Kyle
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or