jQuery in Action, 2nd edition
The moose likes XML and Related Technologies and the fly likes XML String to Document Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "XML String to Document" Watch "XML String to Document" New topic
Author

XML String to Document

Paulo Carvalho
Ranch Hand

Joined: Nov 12, 2008
Posts: 56
Hello

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?

Thanks
Regards
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16480
    
    2

"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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: XML String to Document
 
Similar Threads
Content is not allowed in prolog
Simple XSL transformation
Retrieve objects from XSL transform
reading/updating child node attribute in xml String
Content is not allowed in prolog