XPath表达式以查找其标签名称包含“名称”的元素 [英] XPath expression to find elements whose tag name contains 'Name'

查看:426
本文介绍了XPath表达式以查找其标签名称包含“名称”的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是XPath的新手。

I am a newcomer to XPath.

我正在寻找一种方法来获取标记名称包含特定字符串的所有元素。

I am looking for a way to get all elements whose tag name contains a particular string.

例如,如果我有如下所示的XML,我想获取其标签名称包含单词 Name的所有元素。即,我想获取以下元素:< SquareName> < RectangleName> < ParallelogramName>

For example, if I have XML like below, I want to get all the elements whose tag name contains the word 'Name'. i.e., I want to fetch the following elements: <SquareName>, <RectangleName>, and <ParallelogramName>.

我尝试了 name(), contains()等,但是它不起作用。

I tried some combinations of name(), contains() etc., but it did not work. Please suggest.

<Objects>
 <Four-Sided>
   <Square>
      <SquareName>ABCD</SquareName>
      <Length>4</Length>
      <Height>4</Height>
      <Colour>Blue</Colour>
   </Square>
   <Rectangle>
      <RectangleName>EFGH</RectangleName>
      <Length>10</Length>
      <Height>6</Height>
      <Colour>Brown</Colour>
   </Rectangle>
   <Parallelogram>
      <ParallelogramName>WXYZ</ParallelogramName>
      <Length>12</Length>
      <Height>4</Height>
      <Colour>Black</Colour>
   </Parallelogram>
</Four-Sided>
</Objects>


推荐答案

对于XPath解决方案:

For an XPath solution:

//*[contains(local-name(), 'Name')]

这篇关于XPath表达式以查找其标签名称包含“名称”的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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