XPath question

G

Guest

Hello All:

Is it possible to group parts of an XPath string? I need to retrieve all
ndoes from an xml document where the attribute spellCheckingRequired is equal
to "True" and the attribute controlToRender is equal to "textbox" or
"addressline" or "augmentedtextbox."

Can I group the controlToRender attributes within parentheses or is this not
required?

In other words, can I have :

[(@controlToRender='textbox' or @controlToRender='addressline' or
@controlToRender='augmentedtextbox') and @spellCheckRequired='True']

or will

[@controlToRender='textbox' or @controlToRender='addressline' or
@controlToRender='augmentedtextbox' and @spellCheckRequired='True']

produce the same result?

TIA,
 
C

Chris Fulstow

Hi Joe,

In Xpath, "and" has a higher precedence than "or", and these operators
are left-associative, so your expression will be evaluated as:

[((@controlToRender='textbox' or @controlToRender='addressline') or
(@controlToRender='augmentedtextbox' and @spellCheckRequired='True'))]

You should definitely use parentheses to get the result you're after.

HTH,

Chris
 
G

Guest

Chris,

Thanks for your response.

I want to retrieve all nodes that have spellCheckRequired='True' and have
either @controlToRender='textbox' or @controlToRender='augmentedtextbox' or
@controlToRender='addressline'.

Should I write the expression as:

[((@controlToRender='textbox' or @controlToRender='addressline' or
@controlToRender='augmentedtextbox') and (@spellCheckRequired='True'))]

What would be the best way to write this as an xpath? What would you
recommend?

Thanks,
 
C

Chris Fulstow

Hi Joe,

I'd go with this:

[(@controlToRender='textbox' or @controlToRender='addressline' or
@controlToRender='augmentedtextbox') and @spellCheckRequired='True']

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top