Omar Qawasmeh
Omar Qawasmeh

Reputation: 3

Jdom Xml parser - output duplicate values

How can I print the duplicate tags values using jdom API? For instance having this XML:

<xml> 
    <text> Hello Jdom</text> 
    <tag>Jdom</tag>
    <tag1>hi</tag1> 
    <tag1>bye</tag1> 
</xml>

How can I save both 'tag1' values into an array of strings and print them both? I've tried to use "node.getChildText("tag1");" but it just always takes the first tag's value and omit the other?

Upvotes: 0

Views: 79

Answers (1)

rolfl
rolfl

Reputation: 17707

The trick here is to use the List outputs.... consider:

List<String> values = new ArrayList<>()
for (Element tag : node.getChildren("tag1")) {
    values.add(tag.getText())
}
System.out.println(values.toString())

Upvotes: 0

Related Questions