1
votes

I have a relatively complex XML file following the ReqIF standard that I wish to manipulate using BaseX. When I strip out all of the xlmns attributes in the REQ-IF node, then I can perform XQueries and traverse the file (e.g., //REQ-IF/THE-HEADER) in the XQuery bar, and see the results as expected.

However when I include the xlmns attributes, none of the queries work. 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.

So, how does one express an XQuery (using presumably the namespace information) to get to the innards of this XML file?

<?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>
1

1 Answers

5
votes

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

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)

or another namespace 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)

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)