简体   繁体   中英

XPath expression meaning

I'm new to XPath and want you to consider the following expression, where n is an element:

//n[parent::n and child::n]

Does the expression in [ ] mean that the parent and child node of n must be the same?

Or am I totally wrong? Thank you.

Does the expression in [ ] mean that the parent and child node of n must be the same?

The correctness of your statement depends on what you mean by "the same". If by "the same", you mean "identical", then the statement is clearly incorrect. A node cannot be the parent and child of something at the same time.

On the other hand, if you intended to write "having the same name", then it's true. The expression

//n[parent::n and child::n]

means

Look for all elements with the name n , everywhere in the document, but only if their parent element is also called n and if they have at least one child element called n .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM