如何解决解析来自Soap Envelop请求的数据
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://ACORD.org/Standards/Life/445" xmlns:aaa="http://Life/PolicyDetails/3" xmlns:date="http://exslt.org/dates-and-times">
<soapenv:Header/>
<soapenv:Body>
<aaa:getPolicyDetailResponse>
<policyInfoResp>
<ns:TXLife>
<ns:TXLifeResponse PrimaryObjectID="Holding_1">
<ns:TransRefGUID>rsf4--41c3-8981-5a2c4518a7</ns:TransRefGUID>
<ns:TransType tc="201">Inforce Policy Inquiry</ns:TransType>
<ns:TransExeDate>2020-10-27-05:00</ns:TransExeDate>
<ns:TransExeTime>00:49:16-05:00</ns:TransExeTime>
<ns:TransMode tc="2">Original</ns:TransMode>
<ns:noresponSEOK tc="0">False</ns:noresponSEOK>
<ns:TestIndicator tc="0">False</ns:TestIndicator>
<ns:OLifEExtension vendorCode="AG" ExtensionCode="INI">
<![CDATA[
<![CDATA[[datafile]
Agent.CityState=ATLANTA,GA
Agent.Comp=AGL
Agent.Name=YRVFL KYCHBPO K
Agent.Number=000B078A
Agent.Status=Inactive
Agent.STraddr=4286 DIGKGWZ DNVK KO DYG 202
]]]]>
<![CDATA[>]]>
</ns:OLifEExtension>
</ns:TXLifeResponse>
</ns:TXLife>
</policyInfoResp>
</aaa:getPolicyDetailResponse>
</soapenv:Body>
</soapenv:Envelope>
下面是我编写的用于解析数据的代码,但是我得到了空引用异常。
string contents = System.IO.File.ReadAllText(@"C:\Users\reg\CaReg-output1.txt");
var document = XDocument.Parse(contents);
string url = "http://ACORD.org/Standards/Life/2";
var ns = XNamespace.Get(url);
var xElements = document.Element(ns+"OLifEExtension").Value.ToString();
解决方法
尝试以下操作:
string contents = System.IO.File.ReadAllText(@"C:\Users\reg\CaReg-output1.txt");
XDocument document = XDocument.Parse(contents);
XElement root = document.Root;
XNamespace ns = root.GetNamespaceOfPrefix("ns");
List<string> OLifEExtension = document.Descendants(ns + "OLifEExtension").Select(x => (string)x).ToList();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。