2

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.

Vladimir Dyuzhev
  • 18,130
  • 10
  • 48
  • 62

2 Answers2

1

This one worked for me: //book/title.

Of course this is not precise enough, and cannot be used when there are multiple <xsd:any> in the schema. For my schema though it is sufficient.

I still wonder though what would be the Right Way (tm).

Vladimir Dyuzhev
  • 18,130
  • 10
  • 48
  • 62
1
<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.

Ghislain Fourny
  • 6,971
  • 1
  • 30
  • 37
  • In your case, would declaring "book" and "title" elements in a schema (as direct children of the xs:schema root element) help? – Ghislain Fourny Oct 06 '11 at 22:03
  • 1
    Also, you might be able to circumvent the problem by adding an attribute processContents="skip" to the xsd:any tag. This will not require that the elements matched by xsd:any must be declared. – Ghislain Fourny Oct 06 '11 at 22:08