18
Hello I'm trying to insert a new child element in a Document root element like this:
Document doc = Jsoup.parse(doc);
Elements els = doc.getElementsByTag("root");
for (Element el : els) {
Element j = el.appendElement("child");
}
In the above code only one root tag is in the document so essentially the loop will just run once.
Anyway, the element is inserted as the last element of the root element "root."
Is there any way I can insert a child element as the first element?
Example:
<root>
<!-- New Element must be inserted here -->
<child></child>
<child></chidl>
<!-- But it is inserted here at the bottom insted -->
</root>