How to escape an '&' character between brackets in XPath??

Discussion in 'XML' started by Ramon F Herrera, Jun 15, 2012.

  1. I have an XPath expression as follows:

    /root/table[@titledetail='Black & White']/detailed

    but it is making my XPath programs yell at me.

    TIA,

    -Ramon
    Ramon F Herrera, Jun 15, 2012
    #1
    1. Advertising

  2. Ramon F Herrera <> writes:

    > I have an XPath expression as follows:
    >
    > /root/table[@titledetail='Black & White']/detailed
    >
    > but it is making my XPath programs yell at me.


    What's a "XPath program"? If you hide all the details, the best we can
    do is use a crystal ball.

    XPath doesn't place any restriction on the characters inside a string
    literal. If your XPath expression is placed inside an attribute value in
    an XML element of a XML document, then usual XML-escaping rules apply,
    and & must be written as &amp;

    -- Alain.
    Alain Ketterlin, Jun 15, 2012
    #2
    1. Advertising

  3. Ramon F Herrera wrote:
    >
    > I have an XPath expression as follows:
    >
    > /root/table[@titledetail='Black & White']/detailed
    >
    > but it is making my XPath programs yell at me.


    With XPath that expression should be fine, with XQuery however you need
    /root/table[@titledetail='Black &amp; White']/detailed


    --

    Martin Honnen --- MVP Data Platform Development
    http://msmvps.com/blogs/martin_honnen/
    Martin Honnen, Jun 15, 2012
    #3
  4. On Jun 15, 5:28 am, Alain Ketterlin <-strasbg.fr>
    wrote:
    > Ramon F Herrera <> writes:
    >
    > > I have an XPath expression as follows:

    >
    > > /root/table[@titledetail='Black & White']/detailed

    >
    > > but it is making my XPath programs yell at me.

    >


    > What's an "XPath program"?


    (1) The XQuilla library is an example.

    (2) Stylus Professional is another.

    Both reject the syntax in question.

    -Ramon
    Ramon F Herrera, Jun 15, 2012
    #4
  5. On Jun 15, 5:46 am, Martin Honnen <> wrote:
    > Ramon F Herrera wrote:
    >
    > > I have an XPath expression as follows:

    >
    > > /root/table[@titledetail='Black & White']/detailed

    >
    > > but it is making my XPath programs yell at me.

    >
    > With XPath that expression should be fine, with XQuery however you need
    >    /root/table[@titledetail='Black &amp; White']/detailed
    >



    Thanks, Martin!

    With the xqilla CLI, this one works:

    xqilla -P -i test.xml q1

    where this is the contents of the "q1" file:

    /root/table[@titledetail='Black & White']/detailed

    The "-P" option:

    "-P : Parse in XPath 1.0 compatibility mode (default is XQuery mode)"

    -Ramon
    Ramon F Herrera, Jun 15, 2012
    #5
    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. Replies:
    9
    Views:
    816
  2. Replies:
    10
    Views:
    449
    Dennis Lee Bieber
    Oct 22, 2007
  3. slomo
    Replies:
    5
    Views:
    1,522
    Duncan Booth
    Dec 2, 2007
  4. Replies:
    5
    Views:
    113
  5. Si
    Replies:
    2
    Views:
    131
Loading...

Share This Page