wood burning stoves 2.0
The moose likes XML and Related Technologies and the fly likes XML String to Document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML String to Document" Watch "XML String to Document" New topic

XML String to Document

Paulo Carvalho
Ranch Hand

Joined: Nov 12, 2008
Posts: 57

I have a XML String which I want to convert to a Document object. To do so I made a method "stringToDocument(final String xmlSource)".

However I have a problem. My XML String have the following header:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

When I convert my XML String to a Document object, if I print the resulting Document into a String it has the following header:

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

This causes me problems for next processes that I apply to the generated XML.

How can I convert my XML String to a Document keeping the original header?

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

"Keeping the original header" isn't a reasonable requirement. The prolog is supposed to describe the document it is attached to, and that should be your requirement. So the encoding should declare the actual encoding of the document, and you should only have a "standalone" attribute in your prolog if the document is standalone.
I agree. Here's the link: http://aspose.com/file-tools
subject: XML String to Document
It's not a secret anymore!