Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Escaping characters in xpath

  • 27-05-2009 05:08PM
    #1
    Registered Users, Registered Users 2, Paid Member Posts: 21,262 ✭✭✭✭


    Hi all,

    Anyone know how to do an xpath query for a node that contains a character like "["? Trying to execute a query like /node[2] and it's giving out once it reaches the "[" character.

    Cheers.
    Tagged:


Comments

  • Registered Users, Registered Users 2 Posts: 24 xonet


    Without an example of your XML document and the full XPATH string, it is difficult to see where your problem is.


  • Registered Users, Registered Users 2 Posts: 1,152 ✭✭✭alanmc


    Stark wrote: »
    Hi all,

    Anyone know how to do an xpath query for a node that contains a character like "["? Trying to execute a query like /node[2] and it's giving out once it reaches the "[" character.

    Cheers.

    Because [] is an operator in XPath (much the same way it indexes into an array in Java, it is used to index into a NodeSet in XPath), you are very much discouraged from using either '' in your node names.

    I've just done a small test in XMLSpy and it told me that '[' was an illegal character. It can be used in attribute values or in CDATA, but it has special meaning in XML so should not be used when defining your node names.

    Same goes for the likes of : and .

    Al.


  • Registered Users, Registered Users 2 Posts: 5,618 ✭✭✭Civilian_Target


    [ = [
    ] = ]


  • Registered Users, Registered Users 2 Posts: 5,618 ✭✭✭Civilian_Target


    Goddam, it interpreted the codes as chars :(

    [ = [
    ] = ]


Advertisement