Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...