2017-04-01 74 views
0

我有以下XML數據:反序列化XML具有不同的命名空間UWP

<?xml version="1.0"?> 
    <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"> 
    <e:property> 
     <LastChange> 
     <Event xmlns="urn:schemas-upnp-org:metadata-1-0/RCS/"> 
      <InstanceID val="0"> 
      <RoomVolumes val="uuid:29e07ad9-224f-4160-a2bc-61d17845182a=100"/> 
      <Volume channel="Master" val="100"/> 
      <Mute channel="Master" val="0"/> 
      <RoomMutes val="uuid:29e07ad9-224f-4160-a2bc-61d17845182a=0"/> 
      </InstanceID> 
     </Event> 
     </LastChange> 
    </e:property> 
    </e:propertyset> 

這裏是我的課:

[XmlRoot("propertyset", Namespace = "urn:schemas-upnp-org:event-1-0")] 
public class EventPropertySet 
{ 
    [XmlElement("property")] 
    public List<EventProperty> Properties { get; set; } 
} 

public class EventProperty 
{ 
    [XmlElement("LastChange")] 
    public string LastChange { get; set; } 

    [XmlElement("SinkProtocolInfo")] 
    public string SinkProtocolInfo { get; set; } 

    [XmlElement("IndexerStatus")] 
    public string IndexerStatus { get; set; } 

    [XmlElement("SystemUpdateID")] 
    public string SystemUpdateID { get; set; } 
} 

現在,當我嘗試反序列化XML數據「LastChange」是總是'空'。 當我修改類的EventProperty',像這樣:

public class EventProperty 
{ 
    [XmlElement("LastChange", Namespae = "")] 
    public string LastChange { get; set; } 

    [XmlElement("SinkProtocolInfo", Namespae = "")] 
    public string SinkProtocolInfo { get; set; } 

    [XmlElement("IndexerStatus", Namespae = "")] 
    public string IndexerStatus { get; set; } 

    [XmlElement("SystemUpdateID", Namespae = "")] 
    public string SystemUpdateID { get; set; } 
} 

反序列化拋出異常: XmlException:ReadElementContentAs()方法不能具有子元素的元素上調用。 1號線,103號。

任何想法我應該做什麼?

回答

0

對不起,我發現了這個問題。後面「LastChange」的數據是normaly分析的XML-結構(像這樣:)

<LastChange>&lt;Event xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/RCS/&quot;&gt;&lt;InstanceID val=&quot;0&quot;&gt;&lt;RoomVolumes val=&quot;uuid:29e07ad9-224f-4160-a2bc-61d17845182a=100&quot;/&gt;&lt;Volume channel=&quot;Master&quot; val=&quot;100&quot;/&gt;&lt;Mute channel=&quot;Master&quot; val=&quot;0&quot;/&gt;&lt;RoomMutes val=&quot;uuid:29e07ad9-224f-4160-a2bc-61d17845182a=0&quot;/&gt;&lt;/InstanceID&gt;&lt;/Event&gt;</LastChange> 

現在,當我不WebUtility.HtmlDecode做「DeParse」,萬物工作正常。

相關問題