• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML validation with Schema checks for the sequence of the elements

 
Meghana Meduri
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • 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
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Paul Clapham
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic