【发布时间】:2017-12-13 16:06:02
【问题描述】:
我正在使用 System.Xml.Serialization 将一个类序列化为一个 xdocument。
<tns:RatingRequest xmlns:tns="http://somewebsite/services/rating"
xmlns:tns1="http://somewebsite/services/rating"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://somewebsite/services/rating.xsd ">
<tns:Configuration>
<tns:Client>
<tns:TradingPartnerNum>101010</tns:TradingPartnerNum>
</tns:Client>
</tns:Configuration>
<tns:PickupDate>2017-12-12T00:00:00</tns:PickupDate>
<tns:LatestDeliveryDate>0001-01-01T00:00:00</tns:LatestDeliveryDate>
<tns:Stops>
<tns:Index>1</tns:Index>
</tns:Stops>
</tns:RatingRequest>
我需要的只是第一个具有 tns: 命名空间的节点
<tns:RatingRequest xmlns:tns="http://somewebsite/services/rating"
xmlns:tns1="http://somewebsite/services/rating"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://somewebsite/services/rating.xsd ">
<Configuration>
<TradingPartner>
<TradingPartnerNum>101010</TradingPartnerNum>
</TradingPartner>
</Configuration>
<PickupDate>2017-10-27T00:00:00-05:00</PickupDate>
<DeliveryDate>-05:00</DeliveryDate>
<Stops>
<Stop>
<Index>1</Index>
</stop>
</stops>
</tns:RatingRequest>
有没有一种干净的方法可以做到这一点?
【问题讨论】:
-
两个xml片段描述了不同的数据——子元素的命名空间不同。如果你想要底部的:告诉它使用根命名空间
标签: .net xml vb.net serialization namespaces