문제

I got this particular XML file, it looks like this:

<App01_Storage Type="VOLATILE" Size="200000" Speed="15" LatencyMaxWrite="1" LatencyMaxRead="2" Endurance="12" WorkloadPeak="15" />

In my program I iterate through all children of the root node. My intention is to get all children with their Attributes + values. One child looks like the code above.

System.out.println(node.getName());
System.out.println(node.getAttributes());

The System.Out-Method gives me this 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 I am on the right way. According to my understanding one attribute should look like that: Attribute.Name = Attribute.Value

I want to save the attributes plus values in a different class and dont know how I exactly can get the values plus the name separetaly. The Output I get right now is a List with each entry Attributename = Attributevalue, like one single String. With this single String i cannot work.

Am I seeing something wrong? Hopefully I could explain myself. Thanks a lot:)

도움이 되었습니까?

해결책

node.getAttributes() gives you a list of attributes which you can iterate over again. The ouput you see is just the result of the lists toString() methode which is called when you hand it over to System.out.println().

Do something like this:

for(Attribute attribute : node.getAttributes()) {
    String attributeName = attribute.getName();
    String value = attribute.getValue();
}

There are also other get-methods that already return a certain type (like getIntValue()). Look at the Attribute documentation

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top