Bugs item #1156909, was opened at 2005-03-04 11:50
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1156909&group_id=16035
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: Buggy Document.getXMLEncoding / Document.asXML
Initial Comment:
Try this:
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
public class TestDom4J
{
public static void main(String[] args) throws
Exception {
String xml = "<?xml version='1.0'
encoding='iso-8859-1'?><Message>Hi
there</Message>";
Document doc = DocumentHelper.parseText (xml);
System.out.println ("The encoding is " +
doc.getXMLEncoding ());
System.out.println ("As XML: " + doc.asXML ());
}
}
The result is:
The encoding is null
As XML: <?xml version="1.0" encoding="UTF-8"?>
<Message>Hi there</Message>
Solution:
Step 1: add setXMLEncoding to Interface org.dom4j.Document
Step 2: change DocumentHelper.parseText (String) to
public static Document parseText(String text) throws
DocumentException {
SAXReader reader = new SAXReader();
String encoding = getEncoding(text);
InputSource source = new InputSource(new
StringReader(text));
source.setEncoding(encoding);
Document doc = reader.read(source);
doc.setXMLEncoding (encoding);
return doc;
}
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1156909&group_id=16035
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
dom4j-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev