2017-06-28 6 views
0

xml文字列をオブジェクトとして変換しようとすると問題が発生する。"XML文書(1,40)にエラーがあります。ここでXML(C#)からオブジェクトを作成しようとするとエラーが発生する

は私のコードです:

httpResponse = await httpClient.GetAsync(requestUri); 
      httpResponse.EnsureSuccessStatusCode(); 
      httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); 
      XmlSerializer serializer = new XmlSerializer(typeof(Feed)); 
      StringReader rdr = new StringReader(httpResponseBody); 
      Feed resultingMessage = (Feed)serializer.Deserialize(rdr); 

クラス:

[XmlRoot("feed"), Serializable] 
public class Feed 
{ 
    [XmlElement("title")] 
    public string title { get; set; } 
    [XmlElement("entry")] 
    public List<Entry> Entry { get; set; } 
} 

public class Entry 
{ 
    [XmlElement("content")] 
    public Content content { get; set; } 
} 

public class Content 
{ 
    [XmlElement("properties")] 
    public Properties properties { get; set; } 
} 

public class Properties 
{ 
    [XmlElement("EntityID")] 
    public int properties { get; set; } 
    [XmlElement("Latitude")] 
    public Double latitude { get; set; } 
    [XmlElement("Longitude")] 
    public Double longitude { get; set; } 
    [XmlElement("DisplayName")] 
    public Properties name { get; set; } 
    [XmlElement("__Distance")] 
    public Double distance { get; set; } 
} 

そしてXMLのサンプルを受け取った:私はエラーを取り除く

<?xml version="1.0" encoding="utf-8"?> 
<feed xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> 
<title type="text"></title> 
<id>uuid:ce35d2a9-1966-4bd7-8730-80cff2a0ce58;id=13760</id> 
<rights type="text">© 2017 Microsoft and its suppliers. This API and any results cannot be used or accessed without Microsoft's express written permission.</rights> 
<updated>2017-06-28T19:27:04Z</updated> 
<entry> 
    <id>https://spatial.virtualearth.net/REST/v1/data/c2ae584bbccc4916a0acf75d1e6947b4/NavteqEU/NavteqPOIs('800791175')</id> 
    <title type="text"></title> 
    <updated>2017-06-28T19:27:04Z</updated> 
    <content type="application/xml"> 
     <m:properties> 
      <d:EntityID>800791175</d:EntityID> 
      <d:Latitude m:type="Edm.Double">47.386450</d:Latitude> 
      <d:Longitude m:type="Edm.Double">0.690600</d:Longitude> 
      <d:DisplayName>Au Chantecler</d:DisplayName> 
      <d:LanguageCode>FRE</d:LanguageCode> 
      <d:__Distance m:type="Edm.Double">0.0730920601952144</d:__Distance> 
     </m:properties> 
    </content> 
</entry> 
</feed> 

1,40ではなく1,2である。

ありがとうございます!私は問題を解決し

答えて

1

、私はFeedで、たとえば、要素の名前空間を指定するのを忘れ:

[XmlElement(ElementName = "entry", Namespace = "http://www.w3.org/2005/Atom")] 
public List<Entry> Entries { get; set; } 
+0

ので、我々はそれが解決の問題だ、あなた自身の質問に答えるために感謝を知っています。あなたの答えを[編集]することができますか?たとえば、ルートタイプであなたがそれをどのように解決したかを表示できますか? – dbc

+0

もちろん、今のxmlObjectプロパティは '[XmlElement(ElementName =" entry "、Namespace =" http://www.w3.org/2005/Atom ")のようになります。 公開リストエントリ{get;セット; } ' – BoBasket4

関連する問題