[Tutor] XML Parsing Woes.

Kent Johnson kent37 at tds.net
Thu Jun 1 02:09:52 CEST 2006


doug shawhan wrote:
> Having been dragged kicking and screaming into the fussy, fussy world of 
> XML, I find myself in a pickle.
> 
> I keep getting an error complaining of a missing end-tag:
> 
>  : XML Parse error.
> <BR>XML Error Text: "; nested exception is:
>         org.xml.sax.SAXParseException: The element type "Description" 
> must be terminated by the matching end-tag "</Description>".".
> 
> Now of course, I have saved my output and found the end-tag to be there. 
> I have stripped out everything I can think of that might cause the 
> parser to puke. The string enclosed by the <Description> tags varies 
> from a few characters to a couple of thousand: all fail with the same error.
> 
> I am very new to XML and find it's jargon fairly impenetrable. Is there 
> a handy python module that can one can use to scan XML output for 
> errors? I know the mistake is probably mine ... or perhaps I have 
> actually run on to a bug in the remote application? :-) (Riiiiight!)

Both Internet Explorer and Firefox do a good job of displaying XML and 
showing any errors.

XML tags are case sensitive, make sure the case matches on the start and 
end tags. And of course spelling counts ;)

XML tags must nest properly, both of these will cause an error, one of 
them possibly the error you are seeing:
<Desc>text<Foo>more text</Desc>
<Desc>text</Foo>more text</Desc>

If you are just starting with Python and XML do yourself a favor and use 
ElementTreee instead of the stuff in the standard lib.
http://effbot.org/zone/element.htm

HTH
Kent



More information about the Tutor mailing list