QuickTopic (SM) free message boards QuickTopic (SM) free message boards
Skip to Messages
  Sign In to access your topic list  |New Topic |My Topics|Profile
Upgrade to Pro   Customize, show pictures, add an intro, and more:   QuickTopic Pro...and check out QuickThreadSM
Topic: general online.effbot.org discussion (2005)
Branched from topic: general online.effbot.org discussion
Printer-Friendly Page
All messages    << 11-26  9-10 of 95  1-8 >>
About these ads
Who | When
Messagessort recent-top    (not accepting new messages)
Alan  9
12-18-2004 04:09 PM ET (US)
Preserving comments in ElementTree

Is there a way to preserve comments using ElementTree?

I thought it might have been something I was doing, but even the simplest possible round trip:

ElementTree.ElementTree(file='file-with-comments.xml').write('file2.xml')

... loses comments that were in the original file. Which is catastrophic (ok, means going and getting the backup copy) if you are actually writing back to the same file and had temporarily (you thought) commented something out.
Fredrik LundhPerson was signed in when posted  10
12-19-2004 04:26 PM ET (US)
The ElementTree class is not really designed for round-tripping of human-authored documents; the parsers are only concerned about the infoset, and the tree writer will happily use its own way to encode things, completely ignoring whether something was originally a character reference or an entity or a CDATA section, etc.

You can add comments to trees, though, so it should be possible to tweak one of the parsers so it preserves comments. I'll see if I can dig up an example...
RSS link What's this?
All messages    << 11-26  9-10 of 95  1-8 >>
QuickTopicSM message boards
Over 200,000 topics served
Learn more Frequently asked questions  Acknowledgements
What they're saying about QuickTopic
 Questions, comments, or suggestions? Contact Us
Read our use policy before beginning. We value your privacy; please read our privacy statement.
Copyright ©1999-2008 Internicity Inc. All rights reserved.