Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在XPath中查找特定类型的所有节点_Xpath_Xforms_Orbeon - Fatal编程技术网

如何在XPath中查找特定类型的所有节点

如何在XPath中查找特定类型的所有节点,xpath,xforms,orbeon,Xpath,Xforms,Orbeon,假设我在my view.xml中有以下表单数据实例: <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:exforms="http://www.exforms.org/exf/1-0" xmlns:xsi="http://www.w3.

假设我在my view.xml中有以下表单数据实例:

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:exforms="http://www.exforms.org/exf/1-0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xhtml:head>
<xforms:instance id="instanceData">
    <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <fruits>
     <fruit>
        <fruit-name>Mango</fruit-name>
     </fruit>
     <fruit>
        <fruit-name>Apple</fruit-name>
     </fruit>
     <fruit>
        <fruit-name>Banana</fruit-name>
     </fruit>
</fruits>
</form>
</xforms:instance>
</xhtml:head>
请在XPATH中提供克服此问题的方法

             "//fruit-name"
它应能找到文件层次结构中的所有文件名。

首先: 指出xml有错误的节点结尾可能是一种输入错误

<service>

如果要从实例
instanceData
)中选择与问题中的实例类似的所有
,请执行以下操作:

instance('instanceData')/fruits/fruit/fruit-name
如果这不起作用,一个常见的原因是在包含实例的文档中有一个默认名称空间声明,如:
xmlns=”http://www.w3.org/1999/xhtml“
。如果存在此问题,则需要在声明实例的位置撤消默认命名空间声明,方法是:

<xforms:instance xmlns="" id="instanceData">


(如果这是一个问题,我的建议是不要使用默认的名称空间声明.Ever.而是声明
xmlns:xhtml=”http://www.w3.org/1999/xhtml“
并在所有地方使用
xhtml
前缀。)

@Furgan:在架构众所周知的情况下,启动
/
运算符不是一种好的做法。@Alejandro,这是一个并不总是正确的概括。如果XPath实现有一个可供使用的元素索引(如eXist数据库),那么编写
//fruit name
实际上会更快!另外,在这样一个小实例上运行
//fruit name
可能不会有什么不同。事实上,哪种表达方式是“最好的”取决于几个因素。@ebruchez:首先,这不是一种好的做法。第二,我没有说完整的路径总是更快。但除了实现优化之外,问题在于复杂性:
descedant
axis即使在找到匹配项后也会遍历整个descedant树。而且,语言的表达能力很容易破坏任何优化。在
(..[$complex condition]//element
@Alejandro中思考:仅仅说某件事不是一个好的实践是不够的。这背后一定有一定的道理。一个好的XPath优化器使用索引不需要遍历树,句号。如果您真正想要表达的是“查找文档中的每个
水果名
”元素,那么编写
//水果名
正好表达了这一点。除此之外,两个表达式都很冗长,它们可能只是
实例('instanceData')/fruits/fruit/fruit name
,表达式是生成所有选定节点还是仅生成第一个节点,这在很大程度上取决于所使用的特定XPath引擎的方法。我知道这很旧,但没有人注意到名称空间声明为“xxforms”,与名称空间“xforms”不匹配?我已使用正确的view.xml编辑了我的问题。我没有使用默认名称空间。但它仍然不起作用。@Thangamani,如果这不起作用,我怀疑这是因为你使用这个表达式的方式。这里有一个完整的例子,展示了所有的成果:
instance('instanceData')/fruits/fruit/fruit-name
<xforms:instance xmlns="" id="instanceData">