472,353 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 16731
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 (...
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...
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...
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...
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. ...
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...
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...
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...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.