We are currently trying to remove XMLBeans from our project and trying to get everything to JAXB. While migrating through I came across something that XMLBeans provided natively called XMLCursor
API. Which traversed through an XML and added elements wherever a user felt like. Is there a way to get this done in JAXB or any other XML API? I was researching XMLStreamReader
API, which is pretty close but it doesn't have any method to write to an XML. I am guessing I might have to combine, XMLStreamReader
and XMLStreamWriter
. But cant figure out how to. The latter API doesn't store any location information. Just for some perspective, I have added the old code just let you know what I mean.
// If child elements, insert after last child
if (cur.toLastChild()) {
cur.toEndToken();
cur.toNextToken();
cur.insertElementWithText(elementName, nameSpace, elementValue);
} else {
// Else insert here
cur.toEndToken();
cur.insertElementWithText(elementName, nameSpace, elementValue);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…