Help with transforming dom object

Hello,

I have a bit of code that reads in XML from a string and then modifies the document and then converts it back into a string. The problem is whenever I use the Transformer, the resulting xml is very different from what I originally had. Information like namespaces are no longer there.

I'm inputing:

<test>

<body xmlns="http://www.someplace.com/namespace\">a value goes in here</body>

</test>

And getting back:

<?xml version="1.0" encoding="UTF-8"?><test>

<body>a value goes in here</body>

</test>

Basically I need them to be the same. I've pasted a simple example of what I'm doing below. All this does is read in the xml and then output it back into a String. Any help would be appreciated. Thanks.

publicstaticvoid main(String[] args)throws Exception{

String xml ="<test>\n" +

"\t<body xmlns=\"http://www.someplace.com/namespace\\\">a value goes in here</body>\n" +

"</test>";

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

Document doc = dbf.newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes()));

Transformer trans = TransformerFactory.newInstance().newTransformer();

StringWriter writer =new StringWriter();

trans.transform(new DOMSource(doc),new StreamResult(writer));

System.out.println(writer.getBuffer().toString());

}

[1881 byte] By [babernat_javaa] at [2007-10-3 4:33:24]
# 1
Try to set some output properties on Transformer like:trans.setOutputProperty(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
attilaracza at 2007-7-14 22:37:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Thanks for the reply! That fixed my problem.
babernat_javaa at 2007-7-14 22:37:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...