Xpath3 - 从SOAP消息中获取名称

时间:2016-02-09 08:27:45

标签: xml xpath soap xpath-3.0

这是我的SOAP message,我希望得到 soap:Body 的子元素的名称:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" xmlns:pref="URI_SOAP_WS">
   <soap:Body>
      <pref:book>
         <pref:author>Gambardella, Matthew</pref:author>
         <pref:title>XML Developer's Guide</pref:title>
         <pref:genre>Computer</pref:genre>
         <pref:price>44.95</pref:price>
         <pref:publish_date>2000-10-01</pref:publish_date>
         <pref:description>An in-depth look XML</pref:description>
      </pref:book>
   </soap:Body>
</soap:Envelope>

如何获取<pref:book>的名称?

我想在开关中用于比较。

1 个答案:

答案 0 :(得分:2)

假设您想获得<soap:Body>的直接子项的元素名称,所以在这种情况下它意味着字符串"pref:book",您可以尝试这种方式:

declare namespace soap = "http://www.w3.org/2003/05/soap-envelope/";
/soap:Envelope/soap:Body/*/name()

输出将是pref:book,完全符合要求。在此处使用XPath 2.0进行了测试:http://videlibri.sourceforge.net/cgi-bin/xidelcgi