2017-04-01 120 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”,万物工作正常。