简体   繁体   中英

the proper way to get properties from an XML?

I have the following XML file

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

what is the proper Java way to fetch this data ? I'm getting confused :)

I'm trying the following..

after I loaded the xml file to a Document dom , I tried doing the following:

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

of course i get Null.

I'm missing something.. i don't know what... please assist me .

any information regarding the issue would be greatly appreciated.

thank you

Kfir

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 :)

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