从SOAP异常XML中检索值? [英] Retrieve values from SOAP exception XML?

查看:84
本文介绍了从SOAP异常XML中检索值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自SOAP异常(System.Web.Services.Protocols.SoapException)的'exception.Detail.LastChild.OuterXML'返回给.NET中的程序。



我可以用代码来解析这个字符串,以便检索我需要的值。但我宁愿使用专门设计用于XML结构的方法来做到这一点......尽管这对我来说显然是新的。我试图以多种不同的方式检索我追求的值。但我没有运气,觉得我离解决方案越来越远了。



所以,我的问题:建议的方法是什么检索以下值的值:

附加的xml中的严重性,代码和描述?
提前感谢您的任何见解:)



This is the 'exception.Detail.LastChild.OuterXML' from a SOAP exception( System.Web.Services.Protocols.SoapException) returned to a program in .NET.

I can code to parse this string in a long hand kind of way to retrieve the values i need. But i'd rather do it using methods specifically designed to work with XML structures....even though that is obviously new to me. Ive attempted to retrieve the values i'm after in a number of different ways. But i'm having no luck and feel like i'm getting farther from the solution.

So, my question: What would be the suggested method for retrieving the values for:
Severity, Code and Description in the attached xml?
Thank you in advance for any insights:)

<detail><err:Errors xmlns:err="http://www.zzzz.com/XMLSchema/XOLTWS/Error/v1.1"><err:ErrorDetail><err:Severity>Hard</err:Severity><err:PrimaryErrorCode><err:Code>9120203</err:Code><err:Description>Missing or invalid Address.</err:Description></err:PrimaryErrorCode></err:ErrorDetail></err:Errors></detail>

推荐答案

尝试如下

C#代码:

Try Like Below
C# code:
string xml =@"<detail><err:Errors xmlns:err=""http://www.zzzz.com/XMLSchema/XOLTWS/Error/v1.1""><err:ErrorDetail><err:Severity>Hard</err:Severity><err:PrimaryErrorCode><err:Code>9120203</err:Code><err:Description>Missing or invalid Address.</err:Description></err:PrimaryErrorCode></err:ErrorDetail></err:Errors></detail>";
var element =XElement.Parse(xml);
string Severity =element.Descendants().FirstOrDefault(e => e.Name.LocalName =="Severity" ).Value;
string Code =element.Descendants().FirstOrDefault(e => e.Name.LocalName =="Code" ).Value;
string Description =element.Descendants().FirstOrDefault(e => e.Name.LocalName =="Description" ).Value;





VB代码



VB code

Dim xml As String = "<detail><err:Errors xmlns:err=""http://www.zzzz.com/XMLSchema/XOLTWS/Error/v1.1""><err:ErrorDetail><err:Severity>Hard</err:Severity><err:PrimaryErrorCode><err:Code>9120203</err:Code><err:Description>Missing or invalid Address.</err:Description></err:PrimaryErrorCode></err:ErrorDetail></err:Errors></detail>"
Dim element = XElement.Parse(xml)
Dim Severity As String = element.Descendants().FirstOrDefault(Function(e) e.Name.LocalName = "Severity").Value
Dim Code As String = element.Descendants().FirstOrDefault(Function(e) e.Name.LocalName = "Code").Value
Dim Description As String = element.Descendants().FirstOrDefault(Function(e) e.Name.LocalName = "Description").Value


这篇关于从SOAP异常XML中检索值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆