invalid token problem ?

T

tag

Hi,

I have a xml field:

<Cell Col="2" Row="10">="Actual Asset mix
"&text($C$46,"dd-mmm-yyyy")</Cell>
^
|
this is column 56

and am getting the following error:

xml.sax._exceptions.SAXParseException: <stdin>:21:56: not well-formed
(invalid token)

I have used the :
self.data += saxutils.escape(characters, self.transhash)

and transhash has :

transhash = { '"' : '&quot;', '&' : '&amp;' }

Can anyone please explain why I am getting the error ? What am I
missing ??

THANKS :)
 
T

Thomas =?ISO-8859-1?Q?Kr=FCger?=

tag said:
Can anyone please explain why I am getting the error ? What am I
missing ??

Well the answer is already given:
xml.sax._exceptions.SAXParseException: <stdin>:21:56: not well-formed

Your XML is not well-formed. All quotation marks in CDATA fields (outside of
a tag) must be quoted to &quot;.

You XML should be:

<Cell Col="2" Row="10">=&quot;Actual Asset mix
&quot;&text($C$46,&quot;dd-mmm-yyyy&quot;)</Cell>

Thomas
 
T

tag

Thomas Krüger said:
Your XML is not well-formed. All quotation marks in CDATA fields (outside of
a tag) must be quoted to &quot;.

I got that part :)
You XML should be:
<Cell Col="2" Row="10">=&quot;Actual Asset mix
&quot;&text($C$46,&quot;dd-mmm-yyyy&quot;)</Cell>

but they are - it is complaining about the :
&text part ... the '"' 's are converted into &quot; ...

any other suggestions ?
 
P

Peter Otten

tag said:
I got that part :)


but they are - it is complaining about the :
&text part ... the '"' 's are converted into &quot; ...

any other suggestions ?

I think you misunderstood - the original xml is invalid. In your short
snippet you could remedy that by snippet = snippet.replace("&", "&amp;")
_before_ feeding it to the parser. Unfortunately this doesn't work in the
general case because not all occurences of '&' may be literal ampersand
chars and not all occurences of '<' and '>' may be markup. Therefore what
you need to do is to fix the program that _generates_ the invalid xml not
the one that tries to parse it and fails. If the generating program is in
python, you can use xml.saxutils.escape() to process the literal text
snippets, but only those.

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,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top