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 -
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
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.
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 -
Joined: Jan 23, 2002
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" be considered valid or invalid (since the schema doesn't guarantee that there will be 2 children...)?
Joined: Jun 03, 2000
...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 ]
Joined: Jul 11, 2002
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 -