You can use the XML Parser as you wish (DOM/SAX) and construct a Document object.
Then parse the LoginDetailsVO object and extract the values and set them to the Document object and finally you can convert the Document object to String and return that.
This link would be a starter for you.
Dom Parser
Regards
Santhosh