'Handling distinct nested elements jaxb
There are similar questions such as:
Handling nested elements in JAXB
but they don't exactly address the case when there are elements with distinct names on the same level:
<course>
<name>Calculus</name>
<grades>
<A>Good</A>
<B>Avg</B>
<C>Terrible</C>
</grades>
</course>
The number of grades is dynamic.
What's the pojo for the grades?
Solution 1:[1]
import org.dom4j.*;
Element selectEle = (Element) root.selectSingleNode("/*[name()='course']/*[name()='grades']");
List<Element> elementsList = selectEle.elements();
System.out.println(elementsList.size());
for(Element element : elementsList){
System.out.println(element.getText());
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ??? |
