Finds and returns the first element of specified tag and name. Args: root: `etree.Element` to be searched recursively. tag: The `tag` property of the sought element. name: The `name` attribute of the sought element. Returns: An `etree.Element` with the specified properties.
(root, tag, name)
| 21 | |
| 22 | |
| 23 | def find_element(root, tag, name): |
| 24 | """Finds and returns the first element of specified tag and name. |
| 25 | |
| 26 | Args: |
| 27 | root: `etree.Element` to be searched recursively. |
| 28 | tag: The `tag` property of the sought element. |
| 29 | name: The `name` attribute of the sought element. |
| 30 | |
| 31 | Returns: |
| 32 | An `etree.Element` with the specified properties. |
| 33 | |
| 34 | Raises: |
| 35 | ValueError: If no matching element is found. |
| 36 | """ |
| 37 | result = root.find('.//{}[@name={!r}]'.format(tag, name)) |
| 38 | if result is None: |
| 39 | raise ValueError( |
| 40 | 'Element with tag {!r} and name {!r} not found'.format(tag, name)) |
| 41 | return result |
| 42 | |
| 43 | |
| 44 | def nested_element(element, depth): |
nothing calls this directly
no test coverage detected
searching dependent graphs…