[XPATH] Is this a valid query?

G

gfrommer

Hello Everyone,

I'm writing a server in java, and I want the clients to pass me an
XPath query. I want the XPath queries to be in a specific format
though, I'm pretty sure it's valid but I want your help.

We have several -top level- documents that the user is allowed returned
to them from the query. We don't want them grabbing subchunks of the
XML without that being encased in one of the allowed top documents. For
example, "Person" is the name of one of our top level documents. Is
this query valid?

/Person[/Person/Name="MrCool" AND /Person/Age >42] .... that will
return all Person documents with name "MrCool" and Age > 42, correct?

My REAL question is if we can have very complex predicates in our
XPath, including ()'s to group the parameters, such as:

/Person[ ((/Person/Age > 10 AND /Person/Age < 25) OR
(/Person/Age > 30 AND /Person/Age < 35)) AND
((/Person/Name = "RustyShackleford") OR
(/Person/Name = "DaleGribble")) ]

Is the above query valid? Is there a limit to the length of a
predicate? Also, how do XPath statements (engines) feel about
multi-line XPaths like the one above? Are linebreaks allowed in XPath
statements?

Thanks everyone
 
M

Martin Honnen

how do XPath statements (engines) feel about
multi-line XPaths like the one above? Are linebreaks allowed in XPath
statements?

The section
<http://www.w3.org/TR/xpath#exprlex>
in the XPath 1.0 specification says:
"For readability, whitespace may be used in expressions even though
not explicitly allowed by the grammar: ExprWhitespace may be freely
added within patterns before or after any ExprToken."
thus I think line breaks are allowed in XPath expressions
 
J

Joris Gillis

/Person[/Person/Name="MrCool" AND /Person/Age >42] .... that will
return all Person documents with name "MrCool" and Age > 42, correct?

If the xml looks like:
<root>
<Person>
<Name>MrCool</Name>
<Age>50</Age>
</Person>
</root>
then the Xpath is not quite correct. It should be something like this:

/Person[Name="MrCool" AND Age >42]


regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top