-1

http://rtt.metroinfo.org.nz/RTT/Public/Utility/File.aspx?ContentType=SQLXML&Name=JPPlatform.xml

http://rtt.metroinfo.org.nz/RTT/Public/Utility/File.aspx?Name=JPRoutePositionET.xml&ContentType=SQLXML&PlatformTag=536

Both of those are my sample data which I am pulling down using HttpClient, I want to grab the attributes(?) such as PlatformTag, ETA and the like.

This is using Univeral Apps for Windows 10 mobile and Desktop. But I can't figure out what's going on to do it.

XDocument Document =  XDocument.Parse(RESPONSE_CONSTANT);
var Stops = from Stop in Document.Descendants("Platform")
select new
{
Platformtag = (string)Stop.Attribute("PlatformTag"),
Platformno = (string)Stop.Attribute("PlatformNo")};
foreach (var item in Stops)
BusData.Text = item.Platformtag;
}

Is what I currently have, but nothing comes from it, it just sits there like it sees nothing, from here I don't know enough about XML Parsing to find a next step.

Note: Response_Constant contains data like this: http://rtt.metroinfo.org.nz/RTT/Public/Utility/File.aspx?Name=JPRoutePositionET.xml&ContentType=SQLXML&PlatformTag=536

Jalomba
  • 25
  • 6
  • 2
    What have you tried so far? What problems did you encounter in implementing your solution? – Sumner Evans Sep 20 '16 at 05:02
  • What is it with getting always this as a reply, I have tried the simple XML deserlizers I no longer have my code that I tried since it didn't do what I needed so I got rid of it. I have tried stuff like http://stackoverflow.com/questions/10150785/using-xmltextreader and other XML deserlization techniquies, but since this isn't standard XML they're not going to work the way I want them to – Jalomba Sep 20 '16 at 05:07

1 Answers1

0

Try following. Had to modify xml to replace ampersand.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;

namespace ConsoleApplication14
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            string xml = File.ReadAllText(FILENAME);
            xml = xml.Replace("&", "&");
            StringReader sReader = new StringReader(xml);
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            XmlReader reader = XmlReader.Create(sReader);

            List<Platform> platforms = new List<Platform>();
            while (!reader.EOF)
            {
                if (reader.Name != "Platform")
                {
                    reader.ReadToFollowing("Platform");
                }
                if (!reader.EOF)
                {
                    XElement platform = (XElement)XElement.ReadFrom(reader);

                    platforms.Add(new Platform()
                    {
                        tag = (int)platform.Attribute("PlatformTag"),
                        no = (int?)platform.Attribute("PlatformNo"),
                        name = (string)platform.Attribute("Name"),
                        bearingToRoad = (double?)platform.Attribute("BearingToRoad"),
                        roadName = (string)platform.Attribute("RoadName"),
                        lat = (double)platform.Element(platform.Name.Namespace + "Position").Attribute("Lat"),
                        _long = (double)platform.Element(platform.Name.Namespace + "Position").Attribute("Long")
                    });
                }
            }
        }
    }
    public class Platform
    {
        public int tag { get; set; }
        public int? no { get; set; }
        public string name { get; set; }
        public double? bearingToRoad { get; set; }
        public string roadName { get; set; }
        public double lat { get; set; }
        public double _long { get; set; }
    }
}
jdweng
  • 33,250
  • 2
  • 15
  • 20
  • Disregard that, I got it working I miss-typed something above your code. – Jalomba Sep 20 '16 at 21:33
  • Thanks for the help :) If I have any issues adopting it for any other part of the API I'll post back here and we'll see, but from your code it looks like it's going to be pretty similar – Jalomba Sep 20 '16 at 21:39