Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > SAXParser and preserving special characters

Reply
Thread Tools

SAXParser and preserving special characters

 
 
User
Guest
Posts: n/a
 
      10-31-2003
I am trying to use JDOM's SAXBuilder to parse an XML document that contains
encoded latin-1 characters. After I parse the document, the special
character Strings seem to be replaced with their unicode characters (e.g.,
the String "®" is replaced with a character that has a decimal value of
174); I was expecting that the SAXBuilder would preserve the String
"®". Is it possible to instruct the SAX parser to preserve the special
character encodings?

The following is sample code that illustrates the issue that I am observing:

import java.io.ByteArrayInputStream;

import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

public class TestProductBuilder {

public static void main(String[] args) {
ByteArrayInputStream bis = null;
try {
String product = "<?xml version=\"1.0\"?>" +
"<product>" +
" <name>My Product ®</name>" +
"</product>";

bis = new ByteArrayInputStream(product.getBytes());
SAXBuilder builder = new SAXBuilder(false);
Document productDoc = builder.build(bis);

XMLOutputter outputter = new XMLOutputter("\t", true);
String productFromSAXBuilder = outputter.outputString(productDoc));
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
if (bis != null) { try { bis.close(); } catch (Exception e) {}}
}
}
}

The following is the value for "productFromSAXBuilder":
<?xml version="1.0" encoding="UTF-8"?>
<product>
<name>My Product </name>
</product>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sign preserving Vs value preserving sophia.agnes@gmail.com C Programming 4 12-07-2007 03:14 PM
Remove only special characters and junk characters from a file rvino Perl 0 08-14-2007 07:23 AM
Re: Meta-Characters, Special Characters xah@xahlee.org Java 2 05-31-2007 09:25 AM
How to convert HTML special characters to the real characters with a Java script Stefan Mueller HTML 3 07-23-2006 10:09 PM
integral promotion, arithmetic conversion, value preserving, unsigned preserving??? TTroy C Programming 16 01-31-2005 10:20 PM



Advertisments