• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validate a xpath against XSD

 
Anish Kuti
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21153
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21153
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't yet explained what it means for an XPath expression to be "valid".
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21153
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when/if a particular schema consists of 100+ files, e.g FpML?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic