【发布时间】:2018-12-18 05:45:47
【问题描述】:
我想根据作为参数传递的国家/地区从肥皂响应 xml 中修改/删除节点,在这个 xml 中,如果 Country=”US”,我想删除节点。
我尝试使用下面的代码,但它没有选择节点。
XDocument doc = XDocument.Parse(“XMLString”));
XNamespace xmlns = " http://schemas.xmlsoap.org/soap/envelope/";
var addressNode = doc.Descendants(xmlns + " AddressData").Elements(xmlns + " Country");
任何人都可以建议根据国家/地区删除节点的方法。
示例 Xml:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetAddressDataRs xmlns="xyz.com/Services/Schemas/ Address /v1" xmlns:cm="xyz.com/Services/Schemas/Common/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="xyz.com/Services/Schemas/Address /Schemas.xsd">
<AddressData>
<Id xsi:type="xsd:string">1</Id>
<Add1>ABCDEFG</Add1>
<Add2>XYZABV</Add2>
<City>Las Vegas</City>
<Country>US</Country>
</AddressData>
<AddressData>
<Id xsi:type="xsd:string">1</Id>
<Add1>ABCDEFG</Add1>
<Add2>XYZABV</Add2>
<City>Phoenix</City>
<Country>US</Country>
</AddressData>
<AddressData>
<Id xsi:type="xsd:string">1</Id>
<Add1>ABCDEFG</Add1>
<Add2>XYZABV</Add2>
<City>Kansas City</City>
<Country>US</Country>
</AddressData>
<AddressData>
<Id xsi:type="xsd:string">1</Id>
<Add1>ABCDEFG</Add1>
<Add2>XYZABV</Add2>
<City>Sydney</City>
<Country>Australia</Country>
</AddressData>
<AddressData>
<Id xsi:type="xsd:string">1</Id>
<Add1>ABCDEFG</Add1>
<Add2>XYZABV</Add2>
<City>Townsville</City>
<Country>Australia</Country>
</AddressData>
</GetAddressDataRs>
</s:Body>
</s:Envelope>
【问题讨论】:
-
反序列化xml,然后修改对象怎么样?
标签: c# xml soap xml-parsing response