Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fatal XML Parse Error: Invalid character (Unicode: 0x1D)

407 views
Skip to first unread message

JR

unread,
Nov 5, 2009, 5:43:01 PM11/5/09
to

I apologize up front for not being much of an XML guy. We are trying to use
a canned solution to send barcode strings via XML. The canned solution works
fine. The one issue we are having is that the barcodes are GS1 compliant
meaning we have ASCII character 29 (0x1D) embedded in our barcodes. We want
these strings to contain the character, but the parser just doesn't like them.

Our heading is as follows:
<?xml version="1.0" encoding="utf-8" ?>

Anyone know of a means of passing such characters in an XML string?

Martin Honnen

unread,
Nov 6, 2009, 5:59:54 AM11/6/09
to

XML 1.0 does not allow that character.
I think XML 1.1 allows it if escaped with a character reference
(e.g. & # x 1 D;, without the spaces). However Microsoft does not have
parsers that support XML 1.1.

With the Microsoft .NET framework 2.0 or later you should also be able
to use version="1.0", escape the character as shown above and then parse
it with an XmlReader with XmlReaderSettings where CheckCharacters is set
to false:

XmlReaderSettings xrs = new XmlReaderSettings();
xrs.CheckCharacters = false;

using (XmlReader xr = XmlReader.Create("input.xml", xrs))
{
...
}


The proper way with XML 1.0 however would be to base64 encode such
characters, that way you would be able to pass the file around as XML
1.0 and any XML parser can deal with it.

--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

Ismo Salonen

unread,
Nov 6, 2009, 7:33:43 AM11/6/09
to

Could you use [CDATA] for those parts which use special reserved chars ?

ismo

Martin Honnen

unread,
Nov 6, 2009, 10:49:27 AM11/6/09
to

A control characterlike 0x1D is not a special reserved character, it is
not an allowed character. CDATA sections help to make your data more
readable as you can use
<foo><![CDATA[a < b && b < c]]></foo>
instead of
<foo>a &lt; b &amp;&amp; b &lt; c</foo>
but they don't help to put in characters that are not allowed in XML.

0 new messages