简体   繁体   中英

How can I check if an Element have an specific tag? Jsoup Android

Jsoup Android

How can I check if an Element have an specific tag?

I have a bunch of elements that im using them to display the data in a ListView, such icon, title, description. But some element contain a specific tag name and others don't ("object") that I need to link to the element.

example:

element #1 - no object tag -> skip element

element #2 - no object tag -> skip element

element #3 - contain object tag -> extract object data and display to listview item #3

element #4 - no object tag -> skip element

element #5 - contain object tag -> extract object data and display to listview item #5

element #6 - no object tag -> skip element

Is there something like this:

for(int i=0; i < mElements.select("td.ac6").size(); i++){
    if(mElements.select("td.ac6").get(i)...... // something like containTagName("object")
        // extract the tag data
    else
        // skip the element

I've try mElements.select("td.ac6").get(i).select("object").equals("") and equals(null) and nothing.

if(mElements.select("td.ac6").get(i).select("object").size() > 0)
    // extract the tag data
else
    // skip the element

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