If I understand your problem correctly, you struggle with the fact the name
and bracket
nodes in your xml are not children of a parent node, but just come after each other. I think a solution to get the correct name
element when you have the bracket
element is to use JSOUP's DOM navigation methods, i.e. previousElementSibling()
Here what your loop could look like:
Elements brackets = doc.getElementsByTag("bracket");
for (Element bracket : brackets) {
Element lis = bracket.select("li");
Element name = bracket.previousElementSibling();
System.out.println(name.text());
for (Element li : lis){
System.out.println(li.text());
}
}