[XPATH] Is this a valid query?

Discussion in 'XML' started by gfrommer@hotmail.com, Jan 11, 2005.

  1. Guest

    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
     
    , Jan 11, 2005
    #1
    1. Advertising

  2. wrote:


    > 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
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 11, 2005
    #2
    1. Advertising

  3. Joris Gillis Guest

    > /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,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Fiat W3C !
     
    Joris Gillis, Jan 11, 2005
    #3
  4. the boolean operator is and not AND

    David
     
    David Carlisle, Jan 12, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,983
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,423
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Marrow

    Re: Is this a valid XPath?

    Marrow, Aug 20, 2003, in forum: XML
    Replies:
    0
    Views:
    382
    Marrow
    Aug 20, 2003
  4. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    801
    David Gordon
    May 18, 2005
  5. howa
    Replies:
    3
    Views:
    3,686
    Dimitre Novatchev
    Sep 30, 2007
Loading...

Share This Page