modeling search criteria in xsd [LONG]

L

Leonard Milcin

Hi!

Well, my question is not directly related to Java but is a result of a
project that uses Hibernate criteria API and I wonder if maybe somebody
already solved my problem...

I try to model Hibernate criteria query API in XML using XSD. The idea
is to pass search criteria through web services and return search results.

The problem is that I'm not an expert on XSD and as a result however I
try to model XML like this:

<FindSomeTypeOfObjectRequest>
<And>
<Or>
<Equals>
<Property>id</Property>
<Value>someId</Value>
</Equals>
<Not>
<IsNull>
<Property>name</Property>
</IsNull>
</Not>
</Or>
<SomeOtherCriterion... />
</And>
</FindSomeTypeOfObjectReqest>

i get into O(n^2) amount of XSD where n is number of operators (And, Or,
Equals, Not, IsNull... etc.).

I have found *some* O(n) solution, but XML looks ugly and uses special
Criterion element that always contains a single operator.

<FindSomeTypeOfObjectRequest>
<Criterion>
<And>
<Criterion>
<Or>
<Criterion>
<Equals>...</Equals>
</Criterion>
<Criterion>
<Not>...</Not>
</Criterion>
</Or>
</Criterion>
<Criterion>
<SomeOtherCriterion... />
</Criterion>
</And>
</Criterion>
</FindSomeTypeOfObjectReqest>

The XSD is using recurrency but is quite simple in this case, using one
long xs:choice to list every possible contents of Criterion element.

<xs:element name="FindSomeTypeOfObjectRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Criterion" type="v:Criterion"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="Criterion">
<xs:choice>
<xs:element name="And">
<xs:complexType>
<xs:sequence>
<xs:element name="Criterion" type="v:Criterion" minOccurs="2"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Or">
<xs:complexType>
<xs:sequence>
<xs:element name="Criterion" type="v:Criterion" minOccurs="2"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Not">
<xs:complexType>
<xs:sequence>
<xs:element name="Criterion" type="v:Criterion"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Equals">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="IsNull">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>

Does anybody have any suggestions on what I could do to make XML look
better while still be able to model it in XSD with amount of XSD linear
to number of operators? Is it at all possible? Am I missing something?

Regards,
Leonard Milcin
 
L

Leonard Milcin

Leonard said:
Hi!

Well, my question is not directly related to Java but is a result of a
project that uses Hibernate criteria API and I wonder if maybe somebody
already solved my problem...

I try to model Hibernate criteria query API in XML using XSD. The idea
is to pass search criteria through web services and return search results.

The problem is that I'm not an expert on XSD and as a result however I
try to model XML like this:

<FindSomeTypeOfObjectRequest>
<And>
<Or>
<Equals>
<Property>id</Property>
<Value>someId</Value>
</Equals>
<Not>
<IsNull>
<Property>name</Property>
</IsNull>
</Not>
</Or>
<SomeOtherCriterion... />
</And>
</FindSomeTypeOfObjectReqest>

i get into O(n^2) amount of XSD where n is number of operators (And, Or,
Equals, Not, IsNull... etc.).

Well, O(n*k), to be precise, where n is number of all operators and k is
number of all container operators (operators that work on results from
other operators, like And, Or, Not, etc.)

But it still makes a lot of XSD with all those operators I plan to
implement...

Regards,
Leonard
 
L

Leonard Milcin

Leonard said:
Hi!

Well, my question is not directly related to Java but is a result of a
project that uses Hibernate criteria API and I wonder if maybe somebody
already solved my problem...

I try to model Hibernate criteria query API in XML using XSD. The idea
is to pass search criteria through web services and return search results.

The problem is that I'm not an expert on XSD and as a result however I
try to model XML like this:

<FindSomeTypeOfObjectRequest>
<And>
<Or>
<Equals>
<Property>id</Property>
<Value>someId</Value>
</Equals>
<Not>
<IsNull>
<Property>name</Property>
</IsNull>
</Not>
</Or>
<SomeOtherCriterion... />
</And>
</FindSomeTypeOfObjectReqest>

i get into O(n^2) amount of XSD where n is number of operators (And, Or,
Equals, Not, IsNull... etc.).

(...)

Does anybody have any suggestions on what I could do to make XML look
better while still be able to model it in XSD with amount of XSD linear
to number of operators? Is it at all possible? Am I missing something?

Regards,
Leonard Milcin

For those who would like to know The Solution:

<xs:element name="FindAdaptersRequest">
<xs:complexType>
<xs:sequence>
<xs:element ref="v:Criterion"/>
<xs:element name="FirstResult" type="xs:nonNegativeInteger"/>
<xs:element name="MaxResults" type="xs:positiveInteger"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="Criterion" abstract="true"/>

<xs:element name="And" substitutionGroup="v:Criterion">
<xs:complexType>
<xs:sequence>
<xs:element ref="v:Criterion" minOccurs="2"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="Or" substitutionGroup="v:Criterion">
<xs:complexType>
<xs:sequence>
<xs:element ref="v:Criterion" minOccurs="2"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="Not" substitutionGroup="v:Criterion">
<xs:complexType>
<xs:sequence>
<xs:element ref="v:Criterion"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="Equals" substitutionGroup="v:Criterion">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="IsNull" substitutionGroup="v:Criterion">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>


And, no, JAXB2 doesn't complain;-)

Regards,
Leonard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top