XML not well formed and UTF-8 encoding

P

Philou59

Hi
I am pretty new to XML and I am struggling validating this XML:
<?xml version="1.0" encoding="UTF-8"?>
<XML>×</XML>

This is a (very limited) extract of a huge file we receive from one of
our partners.

My validation tool (and parser!) says this is not a well formed XML
because of the multiplication sign - hexa D7.
As it is encoded in UTF-8, I can't see why some characters would be
refused... I must say I am really confused...

Any help ?
many thanks in advance
 
B

Bjoern Hoehrmann

* Philou59 wrote in comp.text.xml:
I am pretty new to XML and I am struggling validating this XML:
<?xml version="1.0" encoding="UTF-8"?>
<XML>×</XML>

This is a (very limited) extract of a huge file we receive from one of
our partners.

My validation tool (and parser!) says this is not a well formed XML
because of the multiplication sign - hexa D7.
As it is encoded in UTF-8, I can't see why some characters would be
refused... I must say I am really confused...

The lone sequence 0xD7 cannot occur in a UTF-8 encoded document. If it
really does occur like that, then the document is not UTF-8 encoded and
therefore not well-formed XML. You should contact whoever sends you the
document like this, and have them fix it.
 
J

Johannes Koch

Philou59 said:
Hi
I am pretty new to XML and I am struggling validating this XML:
<?xml version="1.0" encoding="UTF-8"?>
<XML>×</XML>

May not be related to your problem, but...
<http://www.w3.org/TR/REC-xml/#dt-name>:
[Definition: A Name is a token beginning with a letter or one of a few
punctuation characters, and continuing with letters, digits, hyphens,
underscores, colons, or full stops, together known as name characters.]
Names beginning with the string "xml", or with any string which would
match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization
in this or future versions of this specification.
 
P

Philippe Poulard

Philou59 said:
Hi
I am pretty new to XML and I am struggling validating this XML:
<?xml version="1.0" encoding="UTF-8"?>
<XML>×</XML>

This is a (very limited) extract of a huge file we receive from one of
our partners.

My validation tool (and parser!) says this is not a well formed XML
because of the multiplication sign - hexa D7.
As it is encoded in UTF-8, I can't see why some characters would be
refused... I must say I am really confused...

Any help ?
many thanks in advance

http://unicode.org/unicode/faq/utf_bom.html#15

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
A

Andy Dingley

Bjoern said:
You should contact whoever sends you the
document like this, and have them fix it.

It's a mistake to validate invalidate documents, even when they're
exchanged between businesses. Take this issue up with the provider of
the document and have them fix it, where it ought to be fixed. If it's
not XML, it's not XML. If it's unpredictably case-insensitive,
unbalanced, misses quotes, insists on particular quote characters, uses
HTML entities or is otherwise broken, then they're just not doing XML,
no mattter how much their pointy-headed conslutant claims they are.

I know this approach is unpopular, especially with your bosses' boss.
If you start applying work-arounds though, the whole thing becomes
increasingly unmaintainable. Just don't go there, whatever the
commercial problem in sorting it out properly.

I can't remember how many times I've gone down this route 8-(
 
J

Joe Kesselman

<XML>×</XML>

If you're going to use XML, you have to honor XML's rules. If you don't,
it isn't XML, period.

As others have said, first thing to do is to rename that element to
something other than XML.

As far as the character being illegal: Not all characters are permitted
in XML; see the spec, available from the W3C's website. XML 1.1 permits
many characters that XML 1.0 didn't, but that requires that the document
be marked as being 1.1 (yours explicitly says 1.0) and requires that
everyone working with the document use tools that support 1.1.

Even in 1.1, I believe some characters are reserved. The traditional
workaround if you really need unconstrained binary data is the same one
used in e-mail: encode the data (typically as base-64) and make
converting it between the encoded form and the actual form the
application's responsibility.




May not be related to your problem, but...
<http://www.w3.org/TR/REC-xml/#dt-name>:
[Definition: A Name is a token beginning with a letter or one of a few
punctuation characters, and continuing with letters, digits, hyphens,
underscores, colons, or full stops, together known as name characters.]
Names beginning with the string "xml", or with any string which would
match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization
in this or future versions of this specification.
 
J

Joseph Kesselman

(And, as others have suggested, you should probably also doublecheck the
UTF-8 encoding rules to make sure you're expressing that character
correctly. Even if it's legal XML, UTF-8 may require that it be encoded
as multiple bytes.)
 
R

Richard Tobin

Bjoern Hoehrmann said:
The lone sequence 0xD7 cannot occur in a UTF-8 encoded document. If it
really does occur like that, then the document is not UTF-8 encoded and
therefore not well-formed XML. You should contact whoever sends you the
document like this, and have them fix it.

Most likely, they have made a mistake with the labelling. Perhaps the
data is in fact in ISO Latin-1. Did your supplier put the declaration
at the top or did you?

-- Richard
 
P

Peter Flynn

Joe said:
> Philou59 wrote in comp.text.xml:

So, I think, are your partners.

0xD7 is a multiplication sign in ISO-8859-1 (and a few others). In UTF-8
it's 0xC397. Either your partners' system is falsifying the encoding of
the document, or their software is crocked.
If you're going to use XML, you have to honor XML's rules. If you don't,
it isn't XML, period.

Yep. If people send you invalid documents, send them straight back and
ask for valid ones. Sometimes you have to hit them with a lart first.
This includes partners.
Even in 1.1, I believe some characters are reserved.

Not reserved, forbidden :)

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top