Search code examples
javaoracle-databasexquerybpel

How to write an XQuery which crosses an xsd:any element?


A schema contains a <xsd:any/> element.

The code, by some external information, knows that in place of any there is a specific XML structure (e.g. foo).

XQuery would be looking as /Root/Child/AnotherChild/book/title.

But XQuery complains that book element is not known, and XQuery thus is not valid.

How can I write a query so that XQuery would accept than anything in <any/> place can be matched dynamically, at runtime?

If environment is of any importance, it is Java, Oracle BPEL, SOA server 1.1.5.


Solution

  • <xsd:any/>
    

    does not really match "any" element - rather, it matches any element declared somewhere in a schema in scope.

    For example, the following schema defines an element containing xsd:any:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://www.example.com/">
      <xs:element name="root">
        <xs:complexType>
          <xs:sequence>
            <xs:any/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    

    Nevertheless, the following query will fail:

    import schema namespace my = "http://www.example.com/";
    validate { <my:root><my:Child/></my:root> }
    

    because my:Child is declared nowhere.

    If the schema is modified as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://www.example.com/">
      <xs:element name="root">
        <xs:complexType>
          <xs:sequence>
            <xs:any/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="Child" type="xs:anyType"/>
    </xs:schema>
    

    then the query should succeed. Of course the element matched by xsd:any may be in another namespace.