wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes validate a xpath against XSD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "validate a xpath against XSD" Watch "validate a xpath against XSD" New topic
Author

validate a xpath against XSD

Anish Kuti
Greenhorn

Joined: May 12, 2008
Posts: 29
We need to validate a xpath using XSD not using sample XML generated from XSD.

Is there any way out ?

why I am saying is .. some XPATH will be based on some value .. which will not be present in sample XML like
like /a/b[c="anish"]/d
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

I don't understand what you mean when you say you want to "validate" an XPath expression using a schema.

But let's suppose that has some meaning, and carry on. If I understand correctly, you only have the schema and you don't have any XML documents which conform to it. So do you want to find out if the expression would be "valid" (whatever that means) with respect to all possible XML documents which conform to the schema? Or do you want to find out if there is one such XML document? I think we need a clearer description of the problem.
Anish Kuti
Greenhorn

Joined: May 12, 2008
Posts: 29
Hi Paul,
Apologies not for making this clear.
I want to
"only have the schema and don't have any XML documents which conform to it. So want to find out if the expression would be "valid" (whatever that means) with respect to all possible XML documents which conform to the schema "

Please let me know if there is any way forward?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Take the XPath expression and create an XML instance document which represents the XPAth location. Then parse this document against the schema.
Anish Kuti
Greenhorn

Joined: May 12, 2008
Posts: 29
Frank ,
Thanks for your reply.

but if a xpath is like /a/b[c="anish"]/d or /a/b[c="kuti"]/d[e=/p/q/[r="some"]/s]/f


then I have to create the xml instance document by looking the value of C in first case and in the 2 nd case c,r .. which will might be complicated ..


Is there any simple and straight forward way out to solve this ?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
What is the actual business requirement that you are trying to meet? This might help with helping you find a solution.

In regards to parsing an arbitrary XPath expression with an XML Schema, there are no open-source tools that do this, or even commercial products, as far as I am awareof.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

You haven't yet explained what it means for an XPath expression to be "valid".
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
I can think of ways in which an XPath expression could clearly be "invalid" and you could detect this from the XSD.

For example if the named element simply didn't exist anywhere or if the nesting of elements is wrong. So I suppose you could look at the XSD and determine that a given XPath statement is not demonsterably invalid and therefore MIGHT return a result.

I suspect thats about the best you could do.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

William Brogden wrote:I can think of ways in which an XPath expression could clearly be "invalid" and you could detect this from the XSD.


I am guessing that the business requirement is to determine whether the XPath expression would return a non-empty list of nodes. After all the XPath expression "/fruit/banana" can be evaluated in the context of any XML document and usually it will return zero nodes. But it isn't "invalid" in any formal sense.

But my guess could be wrong. That's why I asked for clarification.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
What happens when/if a particular schema consists of 100+ files, e.g FpML?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validate a xpath against XSD