提取XML文档元素 [英] Extract element from XML document

查看:180
本文介绍了提取XML文档元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能有人请告诉我如何使用XPath和C#在.NET 3.5框架下下面的XML提取错误元素?



 < XML版本='1.0'编码='UTF-8'>?; 
< SOAP-ENV:信封的xmlns:SOAP-ENV =htt​​p://schemas.xmlsoap.org/soap/envelope/的xmlns:XSI =htt​​p://www.w3.org/2001/ XML模式实例的xmlns:XSD =http://www.w3.org/2001/XMLSchema>
< SOAP-ENV:身体与GT;
< NS1:do_OTA_VehAvailRateRQResponse的xmlns:NS1 =瓮:先锋的web-Web服务-OTA-IOTASOAP-ENV:encodingStyle的=htt​​p://schemas.xmlsoap.org/soap/encoding/>
<返回的xsi:type =XSD:字符串>< OTA_VehAvailRateRS时间戳=2013-04-03T18:16:00TransactionIdentifier =215997103SequenceNmbr =1目标=生产版本=2.0的xmlns =htt​​p://www.opentravel.org/OTA/2003/05>
<错误>
<错误类型=1码=999>公司名称字段无效< /错误>
< /错误>
< / OTA_VehAvailRateRS>
< /返回>
< / NS1:do_OTA_VehAvailRateRQResponse>
< / SOAP-ENV:身体与GT;
< / SOAP-ENV:信封>


解决方案

我们不能告诉你,你错了不要告诉我们你的代码。



但是,我们可以猜测。你的错误元素是一个命名空间,并没有认识到这一点是没有经验的,我会很高兴敢打赌,这是你的错误中这样一个常见的​​错误。



要找到元素在命名空间中,你需要一个路径,例如// E:其中前缀e的约束(在C#API级别)的错误命名空间的 http://www.opentravel.org/OTA/2003/05



(对不起,你不说你是没有经验的。我是从一个事实,即如果你有经验,你会贴出你的XPath代码)推断这一点。


Could someone please tell me how to extract the Errors element from the below XML using XPath and C# under the .NET 3.5 Framework?

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:do_OTA_VehAvailRateRQResponse xmlns:ns1="urn:vanguard-web-webservices-ota-IOTA" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:string"><OTA_VehAvailRateRS TimeStamp="2013-04-03T18:16:00" TransactionIdentifier="215997103" SequenceNmbr="1" Target="Production" Version="2.0" xmlns="http://www.opentravel.org/OTA/2003/05">
  <Errors>
    <Error Type="1" Code="999">COMPANY NAME FIELD IS INVALID</Error>
  </Errors>
</OTA_VehAvailRateRS>
</return>
</ns1:do_OTA_VehAvailRateRQResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

解决方案

We can't tell where you went wrong if you don't show us your code.

But we can guess. Your Errors element is in a namespace, and failing to recognize this fact is such a common error among the inexperienced that I would happily bet this is your bug.

To find elements in a namespace you need a path such as //e:Errors where the prefix e is bound (at the C# API level) to the namespace http://www.opentravel.org/OTA/2003/05.

(Sorry, you don't say that you are inexperienced. I'm inferring this from the fact that if you were experienced, you would have posted your XPath code).

这篇关于提取XML文档元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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