Element vs. Attribute

6 posts, 0 answers
  1. Kyle
    Kyle avatar
    6 posts
    Member since:
    Dec 2012

    Posted 14 Dec 2012 Link to this post

    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??
  2. Kyle
    Kyle avatar
    6 posts
    Member since:
    Dec 2012

    Posted 18 Dec 2012 Link to this post

    I'm still stuck. Any ideas? I really don't want to convert the xml that I receive.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 19 Dec 2012 Link to this post

    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.
  5. Kyle
    Kyle avatar
    6 posts
    Member since:
    Dec 2012

    Posted 19 Dec 2012 Link to this post

    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.
  6. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 21 Dec 2012 Link to this post

    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.
  7. Kyle
    Kyle avatar
    6 posts
    Member since:
    Dec 2012

    Posted 01 Jan 2013 Link to this post

    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017