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    << 94-95  93-93 of 95  77-92 >>
About these ads
Who | When
Messagessort recent-top    (not accepting new messages)
Chris OldsPerson was signed in when posted  93
12-16-2005 07:42 PM ET (US)
I'm using ElementTree 1.2.6 with Python 2.4 on WinXP. With ElementTree.py, I can define entities by setting the entity dict in the XMLTreeBuilder object. With cElementTree, I get different behavior depending on whether or not a DOCTYPE is present in the file. If I have a doctype, parsing works, but I get a segfault when the program finishes. If I do not have a doctype, I get 'undefined entity' exceptions, but no segfault



doc = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE patent-application-publication SYSTEM "pap-v15-2001-01-31.dtd" []>
<patent-application-publication>
<subdoc-abstract>
<paragraph id="A-0001" lvl="0">A new and distinct cultivar of Begonia plant named &lsquo;BCT9801BEG&rsquo;.</paragraph>
</subdoc-abstract>
</patent-application-publication>"""

#from elementtree import ElementTree as et
import cElementTree as et

entities = {
 u'rsquo' : u"&#x2019;", # <!--=single quotation mark, right -->
 u'lsquo' : u"&#x2018;", # <!--=single quotation mark, left -->
}

parser = et.XMLTreeBuilder()
parser.entity.update(entities)
parser.feed(doc)
t = parser.close()
print t.find('.//paragraph').text
RSS link What's this?
All messages    << 94-95  93-93 of 95  77-92 >>
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.