java - In a xml file,How can I get the data in a label depending on another label in the same level of node? -
i have xml file following:
<root> <doc> <str name="name">test1</str> <str name="uri">test1.com</str> </doc> <doc> <str name="name">test2</str> <str name="uri">test1.com</str> </doc> </root>
i want parsing file. name using dom4j.
for(element doc : docs ){ list<element> strs = doc.elements(); for(element str : strs ){ if("name".equals(str.attributevalue("name"))){ system.out.println(str.gettext()); } } }
how can data of 'uri' after getting data of 'name'under same node 'doc'?
thaks lot!
isn't enough following:
for(element doc : docs ){ list<element> strs = doc.elements(); for(element str : strs ){ if("name".equals(str.attributevalue("name"))){ system.out.println(str.gettext()); } if("uri".equals(str.attributevalue("name"))){ system.out.println(str.gettext()); } } }
as you're looping through child of "doc"
Comments
Post a Comment