473,886 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SAX ParseException: 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();
ByteArrayInputS tream bais = new
ByteArrayInputS tream(xmlString .getBytes());
InputSource input = new InputSource(bai s) ;
XMLDocWriter docwriter = new XMLDocWriter();
parser.parse(in put); // <== 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 16822
In article <bq********@net news.proxy.luce nt.com>,
Bobo <bo**@nowhere.c om> wrote:
SAXException : org.xml.sax.SAX ParseException: 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:
ByteArrayInputS tream bais = new ByteArrayInputS tream(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********@net news.proxy.luce nt.com>,
Bobo <bo**@nowhere.c om> wrote:
SAXException : org.xml.sax.SAX ParseException: 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:
ByteArrayInputS tream bais = new

ByteArrayInputS tream(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********@net news.proxy.luce nt.com>,
Bobo <bo**@nowhere.c om> 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
1694
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 that not all html/wml files are xml standard. So I need to change in some way the downloaded html/wml file so that it could be parsed by the Parser. I am looking for some java package that would convert html/wml to xml
8
5286
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, etc.) What I'd like is something as simple as: CREATE TABLE junk (junklet VARCHAR(2500) CHARACTER SET UTF8)); import MySQLdb, re,urllib
0
1518
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 some options that can be selected in Xerces which can make the parsing process faster? For example, i initially used SAXParser xml... ...
4
6077
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 script that grabs some web pages from the web, regex parse the data and stores it localy to xml file for further use.. at first i had no problem using python minidom and everything concerning
2
2639
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 feasible. It would be helpful if people could test the patched Python with their own applications and report any incompatibilities. PEP: 349
24
9084
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 charcaters from an ASCII perspective. I get the following error: > SQLiteCur.execute(sql, row)
0
1227
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 SAXParser(XMLParserConfiguration config); But I don't want to use Xerces classes, only JAXP. Thank you.
1
1712
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; MemBufInputSource buf((const XMLByte*) text.chars( CHARSET_UTF_8
2
3525
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 essential to determine the charset encoding which is usually indentified within the header of the XML file e.g. <?xml version="1.0" encoding="UTF-8" ?> After a query in the xerces-c API documentation I guess that: - XMLDecl(const XMLCh *const...
0
9799
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10770
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10872
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10429
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7139
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4235
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.