Revision 885
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/xpath.py | ||
---|---|---|
144 | 144 |
|
145 | 145 |
def is_instance(elem): return elem.keys != [] and is_id(elem.keys[0]) |
146 | 146 |
|
147 |
def get(parent, xpath, create=False, last_only=None): |
|
147 |
def get(parent, xpath, create=False, last_only=None, limit=1):
|
|
148 | 148 |
'''Warning: The last_only optimization may put data that should be together |
149 | 149 |
into separate nodes''' |
150 | 150 |
if last_only == None: last_only = create |
... | ... | |
167 | 167 |
last_only and (elem.keys == [] or is_instance(elem))) |
168 | 168 |
|
169 | 169 |
# Check each match |
170 |
node = None
|
|
170 |
nodes = []
|
|
171 | 171 |
for child in children: |
172 | 172 |
is_match = elem.value == None or xml_dom.value(child) == elem.value |
173 | 173 |
for attr in elem.keys: |
174 | 174 |
if not is_match: break |
175 | 175 |
is_match = (get(child, attr, False, last_only) != None)\ |
176 | 176 |
== is_positive(attr) |
177 |
if is_match: node = child; break |
|
177 |
if is_match: |
|
178 |
nodes.append(child) |
|
179 |
if limit != None and len(nodes) >= limit: break |
|
180 |
try: node = nodes[0] |
|
181 |
except IndexError: node = None |
|
178 | 182 |
|
179 | 183 |
# Create node |
180 | 184 |
if node == None: |
Also available in: Unified diff
xpath.py: get(): Added basic structure for returning multiple matches. Added limit parameter to select one or many matches.