【问题标题】:XPATH Expression for retrieving the root tag of xml and not the value of the tag [duplicate]用于检索 xml 的根标签而不是标签值的 XPATH 表达式 [重复]
【发布时间】:2013-07-22 21:54:38
【问题描述】:

下面是一个示例 XML。我想检索“根节点标签”。

  1. 我想从下面的 XML 中检索文本“Personnel”。如何使用 XPATH 实现这一点?
  2. 当 age=34 时,如何使用 XPATH 检索文本“Age”。无论我尝试什么,我只得到值(即“34”)而不是标签(即“年龄”)。请注意,我只想检索标签(即“年龄”)而不是“价值”(“34”)。

请帮帮我。

<Personnel>
  <Employee type="permanent">
        <Name>Seagull</Name>
        <Id>3674</Id>
        <Age>34</Age>
   </Employee>
  <Employee type="contract">
        <Name>Robin</Name>
        <Id>3675</Id>
        <Age>25</Age>
    </Employee>
  <Employee type="permanent">
        <Name>Crow</Name>
        <Id>3676</Id>
        <Age>28</Age>
    </Employee>
</Personnel>

【问题讨论】:

    标签: xml xpath tags root


    【解决方案1】:

    使用name函数:

    name(/*)
    

    【讨论】:

    • 谢谢。这解决了问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 2012-03-02
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多