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