简体   繁体   中英

XPath: Find element with most text content

I want to look for paragraphs. I would use the p tag to look for this but I've seen pages that don't use p when they should. To approximate this, I just want to look for the most text in one tag. Any ideas how to find this

Try this: //div/node()[string-length(following-sibling::node()/text()) < string-length(text())]

Actually that's only covering one direction, use this one:

//div/node()[string-length(following-sibling::node()/text()) < string-length(./text()) and not(string-length(preceding-sibling::node()/text()) > string-length(./text()))]

I was using some scrap xml to test this, and the root was <div> so change that to the xml root you're examining.

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