summaryrefslogtreecommitdiff
path: root/src/lxml/xmlid.pxi
diff options
context:
space:
mode:
authorscoder <none@none>2007-12-19 12:02:56 +0100
committerscoder <none@none>2007-12-19 12:02:56 +0100
commit75c225b2bebf834bc645a5bc6d19b698cf587c8d (patch)
tree25abbc1fb17c815ff81112ebe971e3bafa436617 /src/lxml/xmlid.pxi
parente70ec55df662c3fd6ea7ec5b36eacb7fa0741aeb (diff)
downloadpython-lxml-75c225b2bebf834bc645a5bc6d19b698cf587c8d.tar.gz
[svn r3114] r3141@delle: sbehnel | 2007-12-19 09:13:32 +0100
eliminated internal calls to ElementTree() --HG-- branch : trunk
Diffstat (limited to 'src/lxml/xmlid.pxi')
-rw-r--r--src/lxml/xmlid.pxi12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lxml/xmlid.pxi b/src/lxml/xmlid.pxi
index 037ab775..5370969a 100644
--- a/src/lxml/xmlid.pxi
+++ b/src/lxml/xmlid.pxi
@@ -1,3 +1,5 @@
+cdef object _find_id_attributes
+
def XMLID(text):
"""Parse the text and return a tuple (root node, ID dictionary). The root
node is the same as returned by the XML() function. The dictionary
@@ -5,10 +7,14 @@ def XMLID(text):
attributes. The elements referenced by the ID are stored as dictionary
values.
"""
+ global _find_id_attributes
+ if _find_id_attributes is None:
+ _find_id_attributes = XPath('//*[string(@id)]')
+
+ # ElementTree compatible implementation: parse and look for 'id' attributes
root = XML(text)
- # ElementTree compatible implementation: look for 'id' attributes
dic = {}
- for elem in ElementTree(root).xpath('//*[string(@id)]'):
+ for elem in _find_id_attributes(root):
python.PyDict_SetItem(dic, elem.get('id'), elem)
return (root, dic)
@@ -40,7 +46,7 @@ def parseid(source, parser=None):
"""
cdef _Document doc
doc = _parseDocument(source, parser)
- return (ElementTree(doc.getroot()), _IDDict(doc))
+ return (_elementTreeFactory(doc, None), _IDDict(doc))
cdef class _IDDict:
"""A dictionary-like proxy class that mapps ID attributes to elements.