2016-09-20 8 views
-1

http://rtt.metroinfo.org.nz/RTT/Public/Utility/File.aspx?ContentType=SQLXML&Name=JPPlatform.xmlC# SQLXML 역 직렬화 또는

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

그 모두가 내가 HttpClient를를 사용하여 아래로 당겨하고 내 샘플 데이터입니다, 나는 속성을 잡아하려는 오브젝트 (?) 같은 PlatformTag, ETA 및 같은.

이것은 Windows 10 모바일 및 데스크톱 용 Univeral Apps를 사용하고 있습니다. 그러나 나는 그 일을 어떻게 할 것인지 알 수 없다.

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; 
} 

내가 현재 가지고있는,하지만 아무것도는 아무 것도 볼 수없는 것처럼, 그냥 내가 다음 단계를 찾을 XML 구문 분석에 대해 충분히 모른다 여기에서, 거기에 앉아 그것에서 온다.

참고 : Response_Constant이 같은 데이터를 포함 : 다음 http://rtt.metroinfo.org.nz/RTT/Public/Utility/File.aspx?Name=JPRoutePositionET.xml&ContentType=SQLXML&PlatformTag=536

+2

지금까지 해보신 것은 무엇입니까? 솔루션을 구현할 때 어떤 문제가 발생 했습니까? –

+0

답장으로 항상 이것을 얻는 것이 무엇입니까? 간단한 XML deserlizers를 사용해 보았습니다. 필자가 필요로하지 않았으므로 시도하지 않은 코드를 더 이상 가지고 있지 않으므로 제거했습니다. http://stackoverflow.com/questions/10150785/using-xmltextreader 및 기타 XML deserlization techniquies 같은 물건을 시도했지만 표준 XML이 아니므로 원하는 방식으로 작동하지 않을 것입니다 – Jalomba

답변

0

보십시오. 앰퍼샌드를 대체하기 위해 xml을 수정해야했습니다.

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; } 
    } 
} 
+0

무시하십시오. , 나는 코드 위에서 무언가를 잘못 입력했다. – Jalomba

+0

도움을 주셔서 감사합니다 :) API의 다른 부분을 위해이 API를 채택하는 데 문제가 있다면 여기에 다시 게시 해 보겠습니다. 그러나 코드에서 보면 꽤 비슷하게 보입니다. – Jalomba