Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Escaping characters in xpath

Options
  • 27-05-2009 5:08pm
    #1
    Registered Users Posts: 20,975 ✭✭✭✭


    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 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 Posts: 1,137 ✭✭✭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 Posts: 5,618 ✭✭✭Civilian_Target


    [ = [
    ] = ]


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


    Goddam, it interpreted the codes as chars :(

    [ = [
    ] = ]


Advertisement