我需要一些帮助来解析此XML。
我收到以下字符串,我需要获取“ MensajeError”的值。
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<WS_SSPBA_001_SResponse xmlns="http://tempuri.org/">
<WS_SSPBA_001_SResult>
<Estado>boolean</Estado>
<Mensaje>string</Mensaje>
<CodigoError>string</CodigoError>
<MensajeError>error1</MensajeError>
</WS_SSPBA_001_SResult>
</WS_SSPBA_001_SResponse>
</soap:Body>
</soap:Envelope>
我到达了Body标记,但无法进一步解析XML
var xDocument = XDocument.Parse(resultado);
XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
var xElements =
xDocument.Descendants(soapenv + "Body").First()
我尝试解析que标签“”的任何操作均失败。我只需要检索标签“ MensajeError”
谢谢!
您可以只使用LocalName:
var nodeValue = XDocument.Parse(resultado)
.Descendants()
.First(n => n.Name.LocalName == "MensajeError")
.Value;
//nodeValue = "error1"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句