I have an xml document in which I use list of user nodes.
Is there a way to do the following using StAX API?
- update password attribute [for change password option]
- add a new user node
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
StAX doesn’t sound like the easiest option to do what you’re asking in my opinion. However …
The XMLStreamReader interface has a
getLocation()method, so when you encounter a part of the XML String that you find interesting, you could maintain a List of actions to perform afterwards, along with the location where you should perform them.So in rough pseudo-code:
The Action of course needs to be passed a reference to the original XML String/Stream in order to update it. For a String this should be easy. For a Stream possibly not, as once the stream has been read the first time it may not be able to be
reset(). You may have to buffer all the contents yourself as you’re performing the original parse. And you would have to be careful that the actions don’t alter the locations, otherwise subsequent Actions would look at the wrong place in the XML stream.