如何检查Xml的Xpath [英] how to check the Xpath of Xml

查看:94
本文介绍了如何检查Xml的Xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

读取节点的xml的xpath是什么?PatientDrugDetail

what is the xpath of xml to read node PatientDrugDetail

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetPatientFullMedicationHistoryResponse xmlns="https://secure.newcropaccounts.com/V7/webservices">
<GetPatientFullMedicationHistoryResult>
<result>
<Status>OK</Status>
<Message/>
<XmlResponse/>
<RowCount>2</RowCount>
<Timing>0</Timing>
</result>
<patientDrugDetail>

<PatientDrugDetail>
<Name>abc</Name>

</PatientDrugDetail>
<PatientDrugDetail>
<Name>bca</Name>
</PatientDrugDetail>

</patientDrugDetail>
</GetPatientFullMedicationHistoryResult>
</GetPatientFullMedicationHistoryResponse>
</soap:Body>
</soap:Envelope>

推荐答案

你在使用XmlDocument.SelectNodes吗?



如果是这样,我怀疑你遇到了第三行命名空间的问题 - 适用于GetPatientFullMedicationHistoryResponse元素中的所有元素。



为了使用XPath选择所需的元素,您需要使用XmlNamespaceManager指定要使用的前缀。 (这是违反直觉的。)



http://msdn.microsoft.com/en-us/library/4bektfx9(v = vs.110).aspx [ ^ ]



我没有用来做那个方便的代码,我还没有去写一篇文章。





如果我没记错的话,你需要使用;

Are you using XmlDocument.SelectNodes ?

If so, I suspect that you are running into a problem with the namespace on the third line -- which applies to all the elements within the GetPatientFullMedicationHistoryResponse element.

In order to use XPath to select the desired Element you need to specify a prefix to use by using an XmlNamespaceManager. (It's counter-intuitive.)

http://msdn.microsoft.com/en-us/library/4bektfx9(v=vs.110).aspx[^]

I don't have the code I use to do that handy and I still haven't gotten around to writing an article on it.


If I recall correctly, you'll need to use;
System.Xml.XmlNamespaceManager nsm = new System.Xml.XmlNamespaceManager ( Document.NameTable ) ;
nsm.AddNamespace ( someprefix , "https://secure.newcropaccounts.com/V7/webservices" ) ;





然后使用someprefix作为前缀。



Then use someprefix as the prefix.


这篇关于如何检查Xml的Xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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