解析xml以在java中查找元素 [英] parsing xml to find elements in java

查看:114
本文介绍了解析xml以在java中查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须解析一个xml文档,并且必须将所有的元素都放在同一个文件中。我已经经历了例子,他们正在提供元素名称。我不想手动给出元素名称。那么我怎么能得到所有的元素?我只有方法名称为getElementsByTagName(elementName)。有没有其他方法来获取元素?

I have to parse an xml document and have to get all the elements in the same. I have gone through example, where they are just providing the element name. I do not want to give the element name manually. So how could I get all the elements? I am having only the method name getElementsByTagName(elementName). Is there any other method to get the elements?

<bookmap>
<booktitle>
    <mainbooktitle>GMAT in a BOX </mainbooktitle>
</booktitle>
<frontmatter>
    <notices href="Topics/ref_GMAT_box_notices.dita"/>
        <topicref href="Topics/con_GMAT_box_instructions.dita"/>
</frontmatter>
<chapter href="comp_verbal.ditamap" format="ditamap"/>
<chapter href="comp_math.ditamap" format="ditamap"/>
</bookmap>


推荐答案

document.getElementsByTagName("*");

匹配所有元素。

a href =http://download.oracle.com/javase/6/docs/api/org/w3c/dom/Element.html#getElementsByTagName%28java.lang.String%29 =nofollow> javadocs 。

See javadocs.

这篇关于解析xml以在java中查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆