By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,587 Members | 642 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,587 IT Pros & Developers. It's quick & easy.

XPath Validation using xsd Schema

P: n/a
Hi,

Does anyone know how can I validate XPath expressions using xsd
schema?

Thanks

May 18 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
* sy*********@gmail.com wrote in microsoft.public.dotnet.xml:
>Does anyone know how can I validate XPath expressions using xsd
schema?
The data types defined for XML Schema cannot do that; the only type that
would come close would be regular expressions, but XPath expressions are
not regular. You could take the context-free grammar defined in the spec
and use a regular approximation technique to derive a regular expression
but that's as close as you'd get. It would be better and much simpler to
do this in code. An alternative would be to use RELAX NG instead of XML
Schema and implement a custom data type library that does this.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
May 18 '07 #2

P: n/a
<sy*********@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Hi,

Does anyone know how can I validate XPath expressions using xsd
schema?
Do you mean that you'd like to validate that the XPath expression matches
something which is valid according to the schema? I don't know of a way to
do that, but if you validate the document first, then there will be nothing
in it which violates the schema. If you then use the XPath expression, and
don't get any exceptions thrown about the form of the expression being bad,
then you could conclude that the expression is valid "according to the
schema".

BTW, I don't believe that the XML Schema Recommendation defines what it
means for an XPath expression to be valid with respect to a schema.
--
John Saunders [MVP]
May 18 '07 #3

P: n/a
On May 17, 7:47 pm, "John Saunders [MVP]" <john.saunders at
trizetto.comwrote:
<syed.akh...@gmail.comwrote in message

news:11**********************@y80g2000hsf.googlegr oups.com...
Hi,
Does anyone know how can I validate XPath expressions using xsd
schema?

Do you mean that you'd like to validate that the XPath expression matches
something which is valid according to the schema? I don't know of a way to
do that, but if you validate the document first, then there will be nothing
in it which violates the schema. If you then use the XPath expression, and
don't get any exceptions thrown about the form of the expression being bad,
then you could conclude that the expression is valid "according to the
schema".

BTW, I don't believe that the XML Schema Recommendation defines what it
means for an XPath expression to be valid with respect to a schema.
--
John Saunders [MVP]
Thanks for replying.. , yes, you are absolutely right.. I need to
validate the XPath expression according to the schema..
I am actually working on a tool which extract data out of incomming
xml using XPath expressions, these XPath
expressions are inputed into it by some developer(s). Now at XPath
entry time I need to validate them with the schema.

I have a quick and dirty solution myself, that I can generate a fullly
populated sample xml based on xsd
and validate XPath expressions using it. But wanna to look for
something better than that which can work with xsds..
Any suggestions??

Thanks

May 18 '07 #4

P: n/a
An xml schema is used to describe and validate an xml document.

An XPath expression is not an XML document.

Therefore, an xsd schema cannot be used to "XPath expressions".

To do something like this one needs a *parser* for XPath.

One could also try a tool like the XPath Visualizer, which allows the user
to play and learn Xpath the fun way.
Cheers,
Dimitre Novatchev
<sy*********@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Hi,

Does anyone know how can I validate XPath expressions using xsd
schema?

Thanks

May 18 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.