【问题标题】:Contains function returns nodes with all the Substrings. How Can I Avoid that包含函数返回具有所有子字符串的节点。我怎样才能避免这种情况
【发布时间】:2020-06-09 22:23:46
【问题描述】:

我正在使用 './/*[contains(local-name(), "revenue")]' 来检索所有节点与所有变体(大写、小写和混合)完全匹配的 "revenue" 标记而不是将“收入”作为子字符串的节点。

来自以下 xml 数据。我只想检索“revenue”和“Revenue”标签,而不是“interestRevenue”、“transactionrevenue”、“revenueOtherServices”标签

<financial_statement>
  <revenue>123</revenue>
  <Revenue>456</Revenue>
  <interestRevenue>234</interestRevenue>
  <salaries>12</salaries>
  <transactionrevenue>345</transactionrevenue>
  <revenueOtherServices>109</revenueOtherServices>
  <sales>783</sales>
  <costs>746</costs>
  .....
</financial_statement>

有什么办法吗?

提前致谢。

【问题讨论】:

    标签: xml xpath


    【解决方案1】:

    像这样(2.0):

    /financial_statement/*[lower-case(name()) = "revenue"]
    

    对于 xpath 1:

    /financial_statement/*[translate(name(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz") = "revenue"]
    

    【讨论】:

      【解决方案2】:

      要完成@Gilles Quenot 的回答,有两种选择:

      经典形式:

      //*[name()="Revenue" or name()="revenue"]
      

      更复杂:

      //*[string-length(name())=7 and substring(name(),2,7)="evenue"]
      

      【讨论】:

        猜你喜欢
        • 2013-09-14
        • 1970-01-01
        • 1970-01-01
        • 2014-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多