Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to prevent STAX from converting \r\n to \n

843834May 13 2010 — edited May 16 2010
In the code fragment below:

try {
XMLInputFactory f = XMLInputFactory.newInstance();
f.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); // handle CDATA
} catch (Exception e) {
...
}
try {
rXMLStreamReader r = fXMLInputFactory.createXMLStreamReader(
new FileInputStream(filename)); // create stream reader
e = r.next();
String d = r.getText(); // get text that contains \r\n (in CDATA)

} catch(...) {

}

----

getText() returns the proper data -- but the \r\n sequences have been converted to \n.

Is there any way to prevent this? I.e., I like to retrieve exactly what's in the file.

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 13 2010
Added on May 13 2010
11 comments
511 views