473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

SAXParser and preserving special characters

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>
Jul 20 '05 #1
0 3146

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Roy W. Andersen | last post by:
I've been searching google about this for days but can't find anything, so I'm hoping someone here can help me out. I'm trying to create zip-files without needing the zip-file extension in PHP,...
0
by: hitectahir | last post by:
Hi, I have been using the SAXParser class of Xerces to parse some 40-60 K of XML on PersonalJava on an iPAQ. but it takes too much time (almost 30-40 seconds). Can anybody tell me if there are...
3
by: Bobo | last post by:
I am getting the following error while trying to process an XML string with unicode in its content. :12:0: An invalid XML character (Unicode: 0x0) was found in the eement content of the...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
1
by: sonald | last post by:
Dear All, I am working on a module that validates the provided CSV data in a text format, which must be in a predefined format. We check for the : 1. Number of fields provided in the text file,...
1
by: manish23 | last post by:
Hi I am trying to parse an xml document with the following header <?xml version="1.0" encoding="utf-8"?> I am using SAXParser to parse th file as shown in code below: SAXParser sax; ...
2
by: Clive Green | last post by:
Hello peeps, I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and writing MP3 tags). I have been using PHP on the command line (Mac OS X Unix shell, to be precise), and am...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.