XML - Understanding difficulties parsing XML using JDOM -
i got particular xml file, looks this:
<app01_storage type="volatile" size="200000" speed="15" latencymaxwrite="1" latencymaxread="2" endurance="12" workloadpeak="15" /> in program iterate through children of root node. intention children attributes + values. 1 child looks code above.
system.out.println(node.getname()); system.out.println(node.getattributes()); the system.out-method gives me output: app01_storage [[attribute: type="volatile"], [attribute: size="200000"], [attribute: speed="15"], [attribute: latencymaxwrite="1"], [attribute: latencymaxread="2"], [attribute: endurance="12"], [attribute: workloadpeak="15"]]
i guess on right way. according understanding 1 attribute should that: attribute.name = attribute.value
i want save attributes plus values in different class , dont know how can values plus name separetaly. output right list each entry attributename = attributevalue, 1 single string. single string cannot work.
am seeing wrong? explain myself. lot:)
node.getattributes() gives list of attributes can iterate on again. ouput see result of lists tostring() methode called when hand on system.out.println().
do this:
for(attribute attribute : node.getattributes()) { string attributename = attribute.getname(); string value = attribute.getvalue(); } there other get-methods return type (like getintvalue()). @ attribute documentation
Comments
Post a Comment