Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes XML validation with Schema checks for the sequence of the elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML validation with Schema checks for the sequence of the elements" Watch "XML validation with Schema checks for the sequence of the elements" New topic
Author

XML validation with Schema checks for the sequence of the elements

Meghana Meduri
Greenhorn

Joined: Mar 29, 2006
Posts: 27
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

Joined: Jun 03, 2000
Posts: 5040
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


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Meghana Meduri
Greenhorn

Joined: Mar 29, 2006
Posts: 27
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jun 03, 2000
Posts: 5040
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: XML validation with Schema checks for the sequence of the elements
 
Similar Threads
element with ANY content
parsing in jdom
Inhertiting complex type in XML Schema
Inhertiting complex type in XML Schema
XML One liners for the exam....