Diptopol Dam
Diptopol Dam

Reputation: 815

tags of an html page

I want to get all the tags of a html page . I parsed html page and create document(DOM) . But I could not find any method to access all the tags of DOM model. I am using java .

Upvotes: 0

Views: 72

Answers (2)

Johan Sjöberg
Johan Sjöberg

Reputation: 49187

Once you parsed your DOM object you can simply iterate all nodes. Otherwise you could try an xpath expression, like //*.

Quick sample to get you going

public void recurseNodes(Node node) {
    NodeList nodeList = node.getChildNodes();
    for(int i = 0; i < nodeList.getLength(); i++){
        Node childNode = nodeList.item(i);
        // do something with the node .. then recurse into childnode
        recurseNodes(childNode);
    }
}

Upvotes: 1

Alex Hope O&#39;Connor
Alex Hope O&#39;Connor

Reputation: 9684

If you mean getting all the tags in the DOM using javascript, I would recommend using JQuery as you can simply loop over the document like so

$(document).each(function() { $(this).......... });

Is this what you are looking for?

Upvotes: 0

Related Questions