0

我有以下 XML 文件

 <requesting>
 <performing>
  <properties val1="foo"/>
  <properties val2="foo2"/>
 </requesting>
 </performing>

获取此数据的正确 Java 方法是什么?我越来越困惑:)

我正在尝试以下..

将 xml 文件加载到 aDocument dom后,我尝试执行以下操作:

NodeList nl = dom.getElementsByTagName("requesting").item(0).getOwnerDocument().
             getElementsByTagName("performing").item(0).getOwnerDocument().
             getElementsByTagName("properties");

我当然得到空值。

我错过了一些东西..我不知道是什么...请帮助我。

任何有关该问题的信息将不胜感激。

谢谢你

克菲尔

4

1 回答 1

0

ok ok !! I found the solution to the problem!!

instead of getOwnerDocument() I needed to cast item(0) to Document.

means..

Document doc1 = (Document) dom.getElementsByTagName("requesting").item(0);

and so on...

that's it :) simple as that

thanks for your help guys :)

于 2013-01-31T10:30:41.390 回答