locked
Reading XML files in windows store apps RRS feed

  • Question

  • Hi,

    I have an XML file with sample data as below in windows store apps..

    <Exchanges>
      <Exchange DistrictIDFullName="TREPS" DistrictID="TR" ExchangeGroupCode="ASB" Latitude="55.8533" Longitude="-2.38732" />
      <Exchange DistrictIDFullName="DESCTR" DistrictID="DE" ExchangeGroupCode="ABT" Latitude="54.8411" Longitude="-3.28524" />
    </Exchanges>

    I have two requirements.

    1. Need to read all DistrictID's and store it in a list.

    2. Need to make another list with DistrictID's based on the latitude and longitude co-ordinates which lie in within 10 degree wrt my current latitude coordinates. Of course my app has the code to find current co-ordinates.

    Can somebody help me with code snippets or idea to go ahead. It is little urgent for my work.

    Thursday, September 26, 2013 5:55 AM

Answers

  • Hello Naveen,

    I am solved your first question:

    string output = "your xml data";
     ObservableCollection<tempxml> xml1 = new ObservableCollection<tempxml>();
    using (XmlReader red1 = XmlReader.Create(new StringReader(output)))
                {
                    while (red1.Read())
                    {
                        if (red1.IsStartElement())
                        {
                            switch (red1.Name)
                            {
                                case "Exchange":
                                    string DistrictIDFullName = red1["DistrictIDFullName"];
                                    string DistrictID = red1["DistrictID"];
                                    string ExchangeGroupCode = red1["ExchangeGroupCode"];
                                    double Latitude = double.Parse(red1["Latitude"]);
                                    double Longitude = double.Parse(red1["Longitude"]);
                                    xml1.Add(new tempxml
                                    {
                                        DistrictID = DistrictID,
                                        DistrictIDFullName = DistrictIDFullName,
                                        ExchangeGroupCode = ExchangeGroupCode,
                                        Latitude = Latitude,
                                        Longitude = Longitude
                                    });
                                    break;
                            }
                        }
                    }
                }
     public class tempxml
        {
            public string DistrictIDFullName { get; set; }
            public string DistrictID { get; set; }
            public string ExchangeGroupCode { get; set; }
            public double Latitude { get; set; }
            public double Longitude { get; set; }
        }
    

    you can get your whole xml content to this list.

    Thursday, September 26, 2013 7:35 AM