Below is the input and expected output xml. I'm using JDOM parser
Input:
<emp:transactions xmlns:emp="http://www.emp.com/dept"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="">
<emp:transaction xmlns:dept="http://www.emp.com/emp">
<emp:empBooking emp:bookingNbr=""/>
</emp:transaction>
</emp:transactions>
Expected Output:
<emp:transactions xmlns:emp="http://www.emp.com/dept"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="">
<emp:transaction xmlns:dept="http://www.emp.com/emp">
<emp:empBooking emp:bookingNbr=""/>
<emp:flexStringFields>
<emp:flexString01>emp flex 1</emp:flexString01>
</emp:flexStringFields>
</emp:transaction>
</emp:transactions>
Code:
SAXBuilder builder = new SAXBuilder();
Reader in = new StringReader(xmlAsString);
Document document = (Document)builder.build(in);
Element rootNode = document.getRootElement();
List<Element> list = rootNode.getChildren (
"transaction",
Namespace.getNamespace("NS1", "http://www.emp.com/dept")
);
for(Element transaction: list) {
// ...
}
I'm not sure how to add the element emp:flexStringFields
with namespace emp
with its child emp:flexString01
Could you please help me on how to add it?