Paste number 7539: XPath-like Suggestion for Amara

Paste number 7539: XPath-like Suggestion for Amara
Pasted by: sbp
When:7 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+5TF
Channel:#swhack
Paste contents:
Raw Source | XML | Display As
>>> class Element(object): 
...    attributes = {'something': 'blargh'}
...    children = ['p', 'q', 'r']
...    def __div__(self, path): 
...       if path.startswith('@'): 
...          if self.attributes.has_key(path[1:]): 
...             return self.attributes[path[1:]]
...       else: return self.children[self.children.index(path)]
... 
>>> elem = Element()
>>> elem/'@something'
'blargh'
>>> elem/'q'
'q'
>>> 

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.