开发者

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 .


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);
    }
}


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜