开发者

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

开发者 https://www.devze.com 2023-04-11 12:19 出处:网络
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).

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.


<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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号