Hello,

I did not see the XML code in details before I gave the code with ElementTree. In fact with unclosing tags you will get errors at parse time and it will give you
the location of errors.
You could use the module from Stefan which is way way superior than ElementTree which can validate against DTD or XSD and many many other features (speed, etc...)

Regards
Karim

On 01/15/2011 07:53 AM, Stefan Behnel wrote:
Wayne Werner, 15.01.2011 03:25:
On Fri, Jan 14, 2011 at 4:42 PM, Terry Carroll wrote:
On Fri, 14 Jan 2011, Karim wrote:

  from xml.etree.ElementTree import ElementTree

I don't think straight XML parsing will work on this, as it's not valid
XML; it just looks XML-like enough to cause confusion.

It's worth trying out - most (good) parsers "do the right thing" even when they don't have strictly valid code. I don't know if xml.etree is one, but
I'm fairly sure both lxml and BeautifulSoup would probably parse it
correctly.

They wouldn't. For the first tags, the text values would either not come out at all or they would be read as attributes and thus loose their order and potentially their whitespace as well. The other tags would likely get parsed properly, but the parser may end up nesting them as it hasn't found a closing tag for the previous tags yet.

So, in any case, you'd end up with data loss and/or a structure that would be much harder to handle than the (relatively) simple file structure.

Stefan

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to