XPath expression text () - what to specify in text () if it contains a new line

The text looks like this:

text1
text2

How can I put this text in xpath. I tried:

.//* [@id = 'someid'] // h6 [text () = 'text1text2]

.//* [@id = 'someid'] // h6 [text () = 'text1 \ ntext2]

.//* [@id = 'someid'] // h6 [text () = 'text1 text2]

none of them worked

+3


source to share


4 answers


This is working code

   .//*[@id='someid']//h6[. = 'text1text2']

      



Thank.

+1


source


Use .//*[@id='someid']//h6[. = 'text1
text2']

. This assumes that you write the path inside XSLT or XForms where you can use 


to avoid the appearance of a newline character. If you are not using XSLT, you can tell us which host language (e.g. PHP, C #, Java) you are using XPath in.



+1


source


not very elegant, but it works

.//*[@id='someid']//h6[contains(text(), 'text1') and contains(text(), 'text2')]

      

+1


source


You can use normalize-space()

to delete line and compare text without this problem.

//*[@id='someid']//h6[normalize-space(text()) ='text1 text2']

      

0


source







All Articles