我很确定这已经被询问并回答了,我只是找不到
我正在尝试将XML反序列化为POCO。
这是我苦苦挣扎的部分
<Trias version="1.1" xmlns="http://www.vdv.de/trias" xmlns:siri="http://www.siri.org.uk/siri"
这是我的整个XML:
<?xml version="1.0" encoding="UTF-8"?>
<Trias version="1.1" xmlns="http://www.vdv.de/trias" xmlns:siri="http://www.siri.org.uk/siri" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceRequest>
<siri:RequestTimestamp>2012-10-28T20:56:00Z</siri:RequestTimestamp>
<siri:RequestorRef>SEUS</siri:RequestorRef>
<RequestPayload>
<TripRequest>
<Origin>
<LocationRef>
<StopPointRef>8500320</StopPointRef>
</LocationRef>
<DepArrTime>2018-10-09T08:05:51</DepArrTime>
</Origin>
<Destination>
<LocationRef>
<StopPointRef>8500322</StopPointRef>
</LocationRef>
<DepArrTime>2018-10-09T08:05:51</DepArrTime>
</Destination>
<Params>
<NumberOfResults>1</NumberOfResults>
<IncludeTrackSections>true</IncludeTrackSections>
<IncludeLegProjection>true</IncludeLegProjection>
<IncludeIntermediateStops>true</IncludeIntermediateStops>
</Params>
</TripRequest>
</RequestPayload>
</ServiceRequest>
</Trias>
如何在C#中为xmlns:siri
建模?我的班级看起来像这样:
[XmlRoot(nameof(Trias), Namespace = "http://www.vdv.de/trias")]
public class Trias
{
[XmlAttribute("version")]
public string Version { get; set; }
[XmlAttribute("xmlns")]
public string Xmlns { get; set; }
[XmlAttribute("siri")]
public string Siri { get; set; }
}
答案 0 :(得分:1)
尝试将属性XmlAttribute
的{{1}}从Siri
更改为[XmlAttribute("siri")]
[XmlAttribute(Namespace = "http://www.siri.org.uk/siri")]