How the XPATH contains function works

Asked

Viewed 129 times

4

I have a xml thus:

<?xml version="1.0" encoding="UTF-8" ?>

<A x1="ab">
    <B x1="abb">
        <C x1="cc"> Marta </C>
    <B/>
    <B x1="be">
        <C x1="be"> João </C>
    </B>
</A>

And I used the expression XPATH :

//contains(@x1,"b")

I thought through function contains(), would give me all the attributes x1, with the letter b, however the result was:

Boolean='false'
Boolean='true'
Boolean='false'
Boolean='true'
Boolean='false'
Boolean='false'
Boolean='false'
Boolean='false'
Boolean='false'
Boolean='true'
Boolean='false'
Boolean='true'
Boolean='false'
Boolean='false'

Can anyone explain to me why?

  • Its first element B is finished wrong correct to </B>

1 answer

4


The function contains serves to inform if there is an element whose attribute contains a certain value.

It is a logical function so returns only true or falseand is usually used as a parameter.

The expression you’re looking for is:

//*[contains(@x1,"b")]

Where the consultation //* means all elements of the document and the expression between brackets restricts the search to elements whose attribute x1 contain b.

  • 1

    Thank you very much. That was it :)

  • Done. Mt thanks msm kkkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.