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

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

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

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

    data modeling and xsd

    Sunil, Jul 27, 2005, in forum: XML
    Replies:
    1
    Views:
    502
  2. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    982
    Eric Sosman
    Jul 8, 2003
  3. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,583
    Peter Shaggy Haywood
    Sep 20, 2005
  4. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    709
    santosh
    Jul 24, 2007
  5. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    1,255
    Peter Nilsson
    Jan 15, 2008
  6. tenxian
    Replies:
    2
    Views:
    580
    Arne Vajhøj
    Apr 8, 2008
  7. veryhotsausage
    Replies:
    1
    Views:
    2,380
    veryhotsausage
    Jul 4, 2008
  8. Clifford Heath
    Replies:
    2
    Views:
    406
    Clifford Heath
    Feb 7, 2007
Loading...