Xquery 不适用于命名空间 [英] Xquery not working with namespaces
问题描述
我是 xQuery 的初学者,我正在尝试在 XML 文件中列出根节点的所有子类.但是,XML 文档中的根节点在其中定义了名称空间,这意味着我的 xQuery 在引用时不起作用.
I'm a beginner to xQuery, and I'm trying to list all subclasses of the root node in an XML file. However, the root node in the XML doc has namespaces defined within it, which means my xQuery doesn't work when referencing.
对于 doc("/db/books.xml")/bookstore/book 中的 $x返回 $x不返回任何在 bookstore 标签中定义的命名空间
for $x in doc("/db/books.xml")/bookstore/book return $x doesn't return anything with namespaces defined in the bookstore tag
当我从标签中删除命名空间时,查询工作正常.
When I remove the namespaces from the tag, the query works perfectly.
有什么办法可以在不删除 XML 文件中的命名空间的情况下解决这个问题?
Is there any way I can get around this without removing the namespaces in the XML file?
我最终将对数百个名称空间差异很大的 XML 文件执行这些查询
I'll eventually be executing these queries on hundreds of XML files where the namespaces vary considerably
提前致谢
推荐答案
您是否在查询中声明了命名空间?喜欢:
did you declare your namespace in your query? like :
declare namespace ns = "http://example.org";
然后在查询中使用它:
for $x in doc("/db/books.xml")/ns:bookstore/ns:book return $x
这篇关于Xquery 不适用于命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!