Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All i am facing the same problem
can you please help me anybody on this.
I have wcf has returning the xelement with parents,child,subchild elements from that i want to bind to the treeview control as like parent,child ,subchild elements,
Please help me on this
this is wcf has retun as xelement from this i want to do find parent,child,subchild and bind to silverlight4 treeview.
here i am getting object reference not set error.
XML
<?xml version="1.0" encoding="utf-8" ?>
<Regions>
  <Region name="Americas-01">
    <SubRegionOne name="LatinAmerica-05">
    </SubRegionOne>
    <SubRegionTwo name="MCA-60">
    </SubRegionTwo>
    <SubRegionThree name="CAC-37">
    </SubRegionThree>
    <Country name="HPEruope-14">
    </Country>
  </Region>
  <Region name="EMEA-02">
    <SubRegionOne name="LatinAmerica-05">
    </SubRegionOne>
    <SubRegionTwo name="MCA-60">
    </SubRegionTwo>
    <SubRegionThree name="CAC-37">
    </SubRegionThree>
    <Country name="HPEruope-14"></Country>
  </Region>
  <Region name="AsiaPacific-03">
    <SubRegionOne name="LatinAmerica-05">
    </SubRegionOne>
    <SubRegionTwo name="MCA-60">
    </SubRegionTwo>
    <SubRegionThree name="CAC-37">
    </SubRegionThree>
    <Country name="HPEruope-14"></Country>
</Region>
</Regions>

C#
[DataContract]
    public class GeoDataProvider
    {
        [DataMember]
        public string Region { get; set; }
        [DataMember]
        public string SubRegionOne { get; set; }
        [DataMember]
        public string SubRegionTwo { get; set; }
        [DataMember]
        public string SubRegionThree { get; set; }
        [DataMember]
        public string Country { get; set; }
        [DataMember]
        public List<GeoDataProvider> GeoSubItems { get; set; }
    }     XDocument xDocument = XDocument.Load("Mpo_Admin.xml");
            GeoDatatSource = this.GetGeoSource(xDocument.Element("Regions"));
            GeotreeView.ItemsSource = GeoDatatSource;
        private List<GeoDataProvider> GetGeoSource(XElement element)
        {
            try
            {
                return (from Regiondata in element.Elements("Region")
                        select new GeoDataProvider()
                        {
                            Region = Regiondata.Attribute("name").Value,
                            SubRegionOne = Regiondata.Attribute("name").Value,
                            SubRegionTwo = Regiondata.Attribute("name").Value,
                            SubRegionThree = Regiondata.Attribute("name").Value,
                            Country = Regiondata.Attribute("name").Value,
                            GeoSubItems = this.GetGeoSource(Regiondata)
                        }).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Advanced thank you,
Regards,
Narasimha
Posted
Updated 21-Feb-12 22:14pm
v2
Comments
Jaganathan Bantheswaran 22-Feb-12 2:03am    
At what line you are getting the Error?

1 solution

Hi,

In this Article,

C#
categories = this.GetCategories(categoriesXML.Element("categories"));


instead of the above line, use like the below one

C#
categories = this.GetCategories(resultFromWCF); // resultFromWCF is XML Element returned from WCF
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900