invalid token problem ?

Peter Otten __peter__ at web.de
Thu Sep 2 04:23:37 EDT 2004


tag wrote:

> Thomas Krüger <thomas.krueger at gmx.net> wrote in message
> news:<ch1ki4$o78$00$1 at news.t-online.com>...
> 
>> Your XML is not well-formed. All quotation marks in CDATA fields (outside
>> of a tag) must be quoted to ".
> 
> I got that part :)
> 
>> You XML should be:
>> <Cell Col="2" Row="10">="Actual Asset mix
>>  "&text($C$46,"dd-mmm-yyyy")</Cell>
>> 
> 
> but they are - it is complaining about the :
> &text part ... the '"' 's are converted into " ...
> 
> any other suggestions ?

I think you misunderstood - the original xml is invalid. In your short
snippet you could remedy that by snippet = snippet.replace("&", "&") 
_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




More information about the Python-list mailing list