简体   繁体   English

如何处理XQuery / BaseX中的复杂名称空间?

[英]How do you handle complex namespaces in XQuery/BaseX?

I have a relatively complex XML file following the ReqIF standard that I wish to manipulate using BaseX. 我有一个相对复杂的XML文件,它遵循ReqIF标准,希望使用BaseX进行操作。 When I strip out all of the xlmns attributes in the REQ-IF node, then I can perform XQueries and traverse the file (eg, //REQ-IF/THE-HEADER ) in the XQuery bar, and see the results as expected. 当我xlmns REQ-IF节点中的所有xlmns属性时,可以执行XQueries并遍历XQuery栏中的文件(例如//REQ-IF/THE-HEADER ),并按预期查看结果。

However when I include the xlmns attributes, none of the queries work. 但是,当我包含xlmns属性时,所有查询都不起作用。 Even worse, when I select a node in the Map View to copy the path and paste it into the XQuery bar, no results are returned either. 更糟糕的是,当我在“地图视图”中选择一个节点以复制路径并将其粘贴到XQuery栏中时,也不会返回任何结果。

So, how does one express an XQuery (using presumably the namespace information) to get to the innards of this XML file? 那么,如何表达一种XQuery(大概使用名称空间信息)来到达此XML文件的内部?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<REQ-IF xmlns="http://www.omg.org/spec/ReqIF/20110401/reqif.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.omg.org/spec/ReqIF/20110401/reqif.xsd reqif.xsd" xmlns:reqif="http://www.omg.org/spec/ReqIF/20110401/reqif.xsd" xmlns:reqif-xhtml="http://www.w3.org/1999/xhtml" xmlns:rm-reqif="http://www.ibm.com/rm/reqif" xmlns:xhtml="http://www.w3.org/1999/xhtml" >
    <THE-HEADER>
    </THE-HEADER>
    <CORE-CONTENT>
        <REQ-IF-CONTENT>
            <DATATYPES>             
            </DATATYPES>
            <SPEC-TYPES>
            </SPEC-TYPES>
            <SPEC-OBJECTS>
            </SPEC-OBJECTS>
            <SPEC-RELATIONS>
            </SPEC-RELATIONS>
            <SPECIFICATIONS>
            </SPECIFICATIONS>
            <SPEC-RELATION-GROUPS>
            </SPEC-RELATION-GROUPS>
        </REQ-IF-CONTENT>
    </CORE-CONTENT>
</REQ-IF>

Well, look into your favourite XQuery tutorial or in the spec, it shows you can declare a default element namespace https://www.w3.org/TR/xquery-31/#id-default-namespace 好吧,查看您最喜欢的XQuery教程或规范,它显示您可以声明默认元素名称空间https://www.w3.org/TR/xquery-31/#id-default-namespace

declare default element namespace "http://www.omg.org/spec/ReqIF/20110401/reqif.xsd";

/REQ-IF/CORE-CONTENT/REQ-IF-CONTENT/DATATYPES

(example https://xqueryfiddle.liberty-development.net/pPgCcoC ) (示例https://xqueryfiddle.liberty-development.net/pPgCcoC

or another namespace https://www.w3.org/TR/xquery-31/#id-namespace-declaration 或另一个名称空间https://www.w3.org/TR/xquery-31/#id-namespace-declaration

declare  namespace reqif = "http://www.omg.org/spec/ReqIF/20110401/reqif.xsd";

/reqif:REQ-IF/reqif:CORE-CONTENT/reqif:REQ-IF-CONTENT/reqif:DATATYPES

(online at https://xqueryfiddle.liberty-development.net/pPgCcoC/1 ) (在线https://xqueryfiddle.liberty-development.net/pPgCcoC/1

In addition there wild card namespace expressions like /*:REQ-IF and enhanced QNames like ( /Q{http://www.omg.org/spec/ReqIF/20110401/reqif.xsd}REQ-IF ) 此外,还有通配符名称空间表达式,如/*:REQ-IF和增强的QName,如( /Q{http://www.omg.org/spec/ReqIF/20110401/reqif.xsd}REQ-IF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM