什么是用于查找此内容的多分支 xpath 查询? [英] What is a multi branch xpath query for finding this?

查看:19
本文介绍了什么是用于查找此内容的多分支 xpath 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前的 xpath 查询:

This is my current xpath query:

//node:Expr_Assign[subNode:var/node:Expr_Variable/subNode:Name/scalar:string='my_chinese_surname' and subNode:expr/node:Scalar_String/subNode:value/scalar:string='Qiu']

我试图在这个 xml 中找到它:

I'm trying to find it in this xml:

<?xml version="1.0" encoding="UTF-8"?>
<AST xmlns:node="http://nikic.github.com/PHPParser/XML/node" xmlns:subNode="http://nikic.github.com/PHPParser/XML/subNode" xmlns:attribute="http://nikic.github.com/PHPParser/XML/attribute" xmlns:scalar="http://nikic.github.com/PHPParser/XML/scalar">
 <scalar:array>
  <node:Expr_Assign>
   <attribute:startLine>
    <scalar:int>2</scalar:int>
   </attribute:startLine>
   <attribute:endLine>
    <scalar:int>2</scalar:int>
   </attribute:endLine>
   <subNode:var>
    <node:Expr_Variable>
     <attribute:startLine>
      <scalar:int>2</scalar:int>
     </attribute:startLine>
     <attribute:endLine>
      <scalar:int>2</scalar:int>
     </attribute:endLine>
     <subNode:name>
      <scalar:string>my_chinese_surname</scalar:string>
     </subNode:name>
    </node:Expr_Variable>
   </subNode:var>
   <subNode:expr>
    <node:Scalar_String>
     <attribute:startLine>
      <scalar:int>2</scalar:int>
     </attribute:startLine>
     <attribute:endLine>
      <scalar:int>2</scalar:int>
     </attribute:endLine>
     <subNode:value>
      <scalar:string>Qiu</scalar:string>
     </subNode:value>
    </node:Scalar_String>
   </subNode:expr>
  </node:Expr_Assign>
 </scalar:array>
</AST>

目前无法使用.事实上,我什至无法选择标量:数组.

It's not currently working. Infact I can't even select the scalar:array.

查询有什么问题?

我认为这是命名空间.但我无法注册它们,网址已死?http://nikic.github.com/PHPParser/XML/node 这不是领导任何地方.

I figured it was namespaces. But I can't register them, the urls are dead? http://nikic.github.com/PHPParser/XML/node this doesn't lead anywhere.

推荐答案

应该是:

//node:Expr_Assign[subNode:var/node:Expr_Variable/subNode:name/scalar:string='my_chinese_surname' and subNode:expr/node:Scalar_String/subNode:value/scalar:string='Qiu']

注意subNode:name vs subNode:Name

但是我是否可以建议这样的表达式可能更具可读性,尽管我无法根据 XML 的其余部分的外观判断它是否完全按照您想要的方式工作

but might I recommend that an expression like this might be a little more readable although I can't tell if it would work exactly the way you want based on what the rest of your XML looks like

//node:Expr_Assign[.//scalar:string='my_chinese_surname'][ .//scalar:string='Qiu']

另请注意,命名空间 URI 不是 URL,它们不需要可解析即可使用.URL 格式通常用于命名空间 URI,因为一个人通常拥有域,因此可以合理地确定其他人不会通过使用该域中的命名空间 URI 来创建命名空间冲突.命名空间 URI 可以很容易地成为 urn、uuid 或电子邮件地址.

Also note that namespace URIs are not URLs, they don't need to be resolveable to be used. The URL format is commonly used for a namespace URI though because one usually owns the domain and thus is reasonably certain that others won't be creating namespace conflicts by using namespace URIs in that domain. A namespace URI could just as easily be a urn, uuid, or email address.

这篇关于什么是用于查找此内容的多分支 xpath 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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