wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes validating xpath against xml schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "validating xpath against xml schema" Watch "validating xpath against xml schema" New topic
Author

validating xpath against xml schema

Thomas Rochon
Ranch Hand

Joined: Jul 11, 2002
Posts: 72
Hello all,
How can I validate an XPath against an xml schema (not against the actual
xml document) ? So - I want to take a subset of an xml document and I want to validate only this subset against an xml schema.
Any idea how to handle this?
Is there a library supporting me in doing so?
I would be happy to receive some answers
or suggestions from you.
Thanx in advance!
- Thomas -
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Ok, honestly, I have absolutely no clue.
But, your requirement draws a lot of curiosity...
May I ask the circumstances in which you need to do this...
I am positive there's a very valid reason and
I am curious to know what it is.
Thanks.
- madhav


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

Joined: Jan 23, 2002
Posts: 11962
    
    5
Does it have to XPath with which you obtain that "part" to validate? You could just go the blunt force way and create an org.w3c.dom.DocumentFragment out of each piece of the DOM tree you want to validate. Then, write the fragment into an XML string and parse it back into a Document with schema validation turned on.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Thomas Rochon
Ranch Hand

Joined: Jul 11, 2002
Posts: 72
Thanx to both of you!
My requirements are as follows:
I've just a schema and no xml document.
Someone has to enter an xpath (selecting a subset of a currently
not existing xml document).
Now I want to check against the schema whether the xpath is valid
(to the schema) or if it's not.
O.k. - Now you think I'm nuts. But this requirements were given me
by my manager and I'm new to xpath and schemas and stuff.
That's why I posted that (maybe stupid) question into this
forums
- Thomas -
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Could you explain the criteria based on which a given XPath expression is considered to be valid or invalid?
For example, does the XPath need to always match some elements or is it enough that it might or might not match? Considering that element <foo> is specified to have 0..n children of type <bar>, would "foo/bar[2]" be considered valid or invalid (since the schema doesn't guarantee that there will be 2 children...)?
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
...I'm nuts. But this requirements were given me
by my manager


Ok, will sleep on this and post if I have any good thoughts...
Do you get the absolute XPath ? (meaning XPath from the Root
node) or will it be a partial XPath ?

- m
[ February 19, 2004: Message edited by: Madhav Lakkapragada ]
Thomas Rochon
Ranch Hand

Joined: Jul 11, 2002
Posts: 72
Thanx for your help, guys!
Lasse pointed out why this thread can be closed by now:
The requirements that were given me, can't be satisfied
with simply validating an XPaht against a schema. It's possible
that there will occur equivocations regarding the structure
of the xml document which definitely will result in serious
problems. The structure of the xml document would have to be
that much fixed so such equivocations wont exist. But in this
case I'm not forced to validate the XPath against a schema, but
against the xml document by itself.
Thanx, Lasse & Madhav!
You both did me a great favor!
Best regards,
- Thomas -
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validating xpath against xml schema
 
Similar Threads
How to validate an XML schema i.e. Validate an XSD file
merge XMl documents using schema to determine sequencing
validate a xpath against XSD
XML Schema Help
DTD Validation Using an Editor