File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
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: 57
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: 18541
    
    8

"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
 
Similar Threads
Content is not allowed in prolog
reading/updating child node attribute in xml String
Content is not allowed in prolog
Retrieve objects from XSL transform
Simple XSL transformation