Skip to content

Instantly share code, notes, and snippets.

@pckujawa
Created March 30, 2012 03:01
Show Gist options
  • Save pckujawa/2246101 to your computer and use it in GitHub Desktop.
Save pckujawa/2246101 to your computer and use it in GitHub Desktop.
xml parsing using different libraries
################################## 15 ##################################
def hard():
# Example 1
try:
import twisted
help(twisted) # (this may not be as hard as I think, though)
except:
pass
# Example 2
import xml.dom.minidom
document = xml.dom.minidom.parseString(
'''<menagerie><cat>Fluffers</cat><cat>Cisco</cat></menagerie>''')
menagerie = document.childNodes[0]
for node in menagerie.childNodes:
if node.childNodes[0].nodeValue== 'Cisco' and node.tagName == 'cat':
return node
def easy(maybe):
# Example 1
try:
import gevent
help(gevent)
except:
pass
# Example 2
import lxml
menagerie = lxml.etree.fromstring(
'''<menagerie><cat>Fluffers</cat><cat>Cisco</cat></menagerie>''')
for pet in menagerie.find('./cat'):
if pet.text == 'Cisco':
return pet
print "If the implementation is hard to explain, it's a bad idea."
print 'If the implementation is easy to explain, it may be a good idea.'
@pckujawa
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment