473,382 Members | 1,526 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,382 software developers and data experts.

Unicode and SAXParser

I am getting the following error while trying to process an XML string with
unicode in its content.

[Fatal Error] :12:0: An invalid XML character (Unicode: 0x0) was found in
the eement content of the document.
SAXException: org.xml.sax.SAXParseException: An invalid XML character
(Unicode:0x0) was found in the element content of the document.

The piece of code that generates this error is the following:

DOMParser parser = new DOMParser();
ByteArrayInputStream bais = new
ByteArrayInputStream(xmlString.getBytes());
InputSource input = new InputSource(bais) ;
XMLDocWriter docwriter = new XMLDocWriter();
parser.parse(input); // <== right here is where I get this error at
run time

Could you please give me a piece of advise what to do? I am pretty new to
XML. I am using apache xerces java API.

Any help or hint would be appreciated!

Yung
Jul 20 '05 #1
3 16800
In article <bq********@netnews.proxy.lucent.com>,
Bobo <bo**@nowhere.com> wrote:
SAXException: org.xml.sax.SAXParseException: An invalid XML character
(Unicode:0x0) was found in the element content of the document.
Well somehow you've got a null in the input stream, which is not
allowed. Assuming that xmlString didn't contain a null:
ByteArrayInputStream bais = new ByteArrayInputStream(xmlString.getBytes());


the obvious way for this could happen would be for getBytes() to be
encoding the string in a different encoding from that used to parse
the resulting byte stream. That's quite likely - the parser is
presumably using UTF-8 by default and getBytes uses the platform's
default encoding which is probably not UTF-8, but I can't see how
you're likely to get a null with the common default encodings. Is
there an XML declaration at the start of the string, and if so is it
specifying the encoding?

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #2
Thanks for the reply. No. This happens be an error message from a telnet
session which has a lot of escape characters. Right now I am thinking about
ignoring them and escape them. If there's a way to pass all those
characters, it would be great to know. Do you have any thoughts on this?

Thanks,
Yung

"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:bq***********@pc-news.cogsci.ed.ac.uk...
In article <bq********@netnews.proxy.lucent.com>,
Bobo <bo**@nowhere.com> wrote:
SAXException: org.xml.sax.SAXParseException: An invalid XML character
(Unicode:0x0) was found in the element content of the document.
Well somehow you've got a null in the input stream, which is not
allowed. Assuming that xmlString didn't contain a null:
ByteArrayInputStream bais = new

ByteArrayInputStream(xmlString.getBytes());
the obvious way for this could happen would be for getBytes() to be
encoding the string in a different encoding from that used to parse
the resulting byte stream. That's quite likely - the parser is
presumably using UTF-8 by default and getBytes uses the platform's
default encoding which is probably not UTF-8, but I can't see how
you're likely to get a null with the common default encodings. Is
there an XML declaration at the start of the string, and if so is it
specifying the encoding?

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.
FreeBSD rules!

Jul 20 '05 #3
In article <bq********@netnews.proxy.lucent.com>,
Bobo <bo**@nowhere.com> wrote:
Thanks for the reply. No. This happens be an error message from a telnet
session which has a lot of escape characters. Right now I am thinking about
ignoring them and escape them. If there's a way to pass all those
characters, it would be great to know. Do you have any thoughts on this?


You certainly need to do something about them!

Most control characters are illegal in XML 1.0. 1.1 is more liberal,
but you probably don't want to rely on 1.1 just for this, and it won't
help with nuls. If you want to preserve the characters you could:

(a) translate them into elements, e.g. <control code="0"/>
(b) translate them into other characters, perhaps ones in the
unicode private use area (you would probably translate them
into character references, e.g. &#xE000;).

-- Richard

--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #4

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

Similar topics

0
by: Maciek Zywno | last post by:
hello experts! I am using java to create URL connection and get wml or html file fro mremote server. Then I am using SAXParser ( org.xml.sax.helpers.DefaultHandler ) to parse it. The problem is...
8
by: Bill Eldridge | last post by:
I'm trying to grab a document off the Web and toss it into a MySQL database, but I keep running into the various encoding problems with Unicode (that aren't a problem for me with GB2312, BIG 5,...
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...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
2
by: Neil Schemenauer | last post by:
python-dev@python.org.] The PEP has been rewritten based on a suggestion by Guido to change str() rather than adding a new built-in function. Based on my testing, I believe the idea is...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
0
by: Undeclared | last post by:
Hello! My goal is to use JAXP for creating SAX parser with my own XMLParserConfiguration. For example, in package org.apache.xerces.parsers there is a constructor: public...
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: christian.eickhoff | last post by:
Hello Everyone, I am facing a problem which should be relatively easy to solve for XML or XERCES experts. I am parsing my XML instance using xerces-c SAXParser. For internal purposes, it is...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.