modeling search criteria in xsd [LONG]

Discussion in 'Java' started by Leonard Milcin, May 18, 2008.

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

    --
    Simplicity is the ultimate sophistication.
    -- Leonardo da Vinci
    Leonard Milcin, May 18, 2008
    #1
    1. Advertising

  2. Leonard Milcin wrote:
    > 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

    --
    Simplicity is the ultimate sophistication.
    -- Leonardo da Vinci
    Leonard Milcin, May 18, 2008
    #2
    1. Advertising

  3. Leonard Milcin wrote:
    > 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
    Leonard Milcin, May 18, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VisionSet
    Replies:
    2
    Views:
    310
    VisionSet
    Oct 28, 2004
  2. Sunil

    data modeling and xsd

    Sunil, Jul 27, 2005, in forum: XML
    Replies:
    1
    Views:
    421
  3. Veli-Pekka Tätilä
    Replies:
    4
    Views:
    309
    Veli-Pekka Tätilä
    Dec 15, 2005
  4. tenxian
    Replies:
    2
    Views:
    415
    Arne Vajhøj
    Apr 8, 2008
  5. Clifford Heath
    Replies:
    2
    Views:
    180
    Clifford Heath
    Feb 7, 2007
Loading...

Share This Page