XML Parsing Question

I am reading the input stream from an HTTP Post. The data is coming in XML format. The incoming document looks like this:

<transaction>

<user>USERNAME</user>

<password>PASSWORD</password>

<form>FORMNAME</form>

<xmldoc>

<request>

<partner>PARTNERNAME</partner>

<fields>

<field id="536871007">DATA</field>

</fields>

</request>

</xmldoc>

</transaction>

I am able to parse out the user, password, and form data, but not the xmldoc tag. I want to get everything under and including the request tag and then store that. I am using JDOM. So far I have:

ServletInputStream in = req.getInputStream();

Document doc = builder.build(in);

Element root = doc.getRootElement();

RequestData rd =new RequestData();

rd.setFormName(root.getChildText("form"));

rd.setPassword(root.getChildText("password"));

rd.setUser(root.getChildText("user"));

Element xmldoc = root.getChild("xmldoc");

req is my HTTPServletRequest object and rd is a custom data class. The closest i have come is to use xmldoc.getValue, but that strips out my XML tags, and i want to preserve them along with the data inside them. I just want to parse out

<request>

<partner>PARTNERNAME</partner>

<fields>

<field id="536871007">DATA</field>

</fields>

</request>

and store it.

Thanks.

[1767 byte] By [phpolla] at [2007-11-26 15:00:20]
# 1

You should consider using the asXML() method of DOM4J's Node interface. This method returns a complete textual representation of the node, including not only its text content but also the enclosing tags and its attributes. This is how it works:import org.dom4j.Document;

import org.dom4j.Element;

...

Document doc = <your XML document>;

Element root = doc.getRootElement();

Element request = root.element("xmldoc").element("request");

String stringToStore = request.asXML();

The stringToStore variable stores the <request> element as an unstripped string:<request>

<partner>PARTNERNAME</partner>

<fields>

<field id="536871007">DATA</field>

</fields>

</request>

prgguya at 2007-7-8 8:49:09 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Thanks! That worked great.
phpolla at 2007-7-8 8:49:09 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
You can do the same with JDOM: http://forum.java.sun.com/thread.jspa?threadID=5126101
prgguya at 2007-7-8 8:49:09 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...