• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

XML validation with Schema checks for the sequence of the elements

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I try to validate my xml document with schema, it checks if the input xml has the elements in the order/sequence they are defined in the schema.

But problem is, my xml document can contain these elements in any sequence.
Example if elements x, y,z are defined in the schema in the sequence below.
<x>
<y/>
<z/>
</x>

then my xml document may not necessarily get the elements in the same sequence.
All I want to check is if my xml has those elements in them. I am not much considered about the sequence.

Is there is any setting while validating xml document which ignores the sequence?

I am using JDOM.

Your input is very much appreciated.

Thank you.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm.....usually we use schemas are used to define the structure of your XML and validate the structure. So if you have random elements in your XML, then its debatable whether you need a schema or otherwise. That said, you can as well write a schema that does not enforce......welll.....nooo.

The more I think about this the more I am inclined to say I wouldn't bother with a schema. If I were to do this, I would get rid of the schema (if that is possible) and move that business logic into the JDOM code. Logically validate if the elements are present or otherwise.

I am interested in any other ways of doing this. Other thoughts please.

- m
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you tell us a bit more about how you have written your schema?

The usual way of indicating that some elements may occur in any order is to use "xs:all". For example:



Are you currently using the ordered grouping "xs:sequence" instead?
 
Meghana Meduri
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for both your replys.
You are correct Frank, The schema is defined with ordered grouping that is xs:sequence.

I thought of using xs:all but the schema is owned by some other group and I cannot change it. Hence, I was thinking if there is any way that this feature can be switched programatically.

The XML document that is fed into my application gets processed by an XSLT. Hence as a work around, we have updated XSLT to ensure the sequence of the elements.
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't call that a "workaround". The schema says the elements are supposed to be in a certain sequence. So changing your XSLT to produce the elements in that sequence would be called a "bug fix".
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO, bug fix is something that fixes the source of the bug. So, I would use the term workaround. ;)

Anyways, glad to know the xs:all feature. Never used it and I faintly remember reading it, atleast it didn't register in my brain till now that is.

- m
 
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic