java - How to get attribute value? DomParser -
this question has answer here:
- getting attribute value in xml element 3 answers
i have method:
private static void print(nodelist nodelist) { (int = 0; < nodelist.getlength(); i++) { node t = nodelist.item(i); if (t.getnodetype() == node.element_node) { system.out.println("node: " + t.getnodename()); system.out.println("values " + t.gettextcontent()); system.out.println("------------------------------"); } if (doc.haschildnodes()) { print(t.getchildnodes()); } } }
it displays contents of xml document:
<card> <thema>people</thema> <type sent="true">advertising</type> <country>india</country> <year>1966</year> <authors><author>julia</author></authors> <valuable>historical</valuable> </card>
but not show value of attribute in node "sent". how can modify it? thanks!
use method getattributes list of attributes of node:
a
namednodemap
containing attributes of node (if element) or null otherwise.
Comments
Post a Comment