Return the attributes of the matched xpath element. CLI Example: .. code-block:: bash salt '*' xml.get_attribute /tmp/test.xml ".//element[@id='3']"
(file, element)
| 62 | |
| 63 | |
| 64 | def get_attribute(file, element): |
| 65 | """ |
| 66 | Return the attributes of the matched xpath element. |
| 67 | |
| 68 | CLI Example: |
| 69 | |
| 70 | .. code-block:: bash |
| 71 | |
| 72 | salt '*' xml.get_attribute /tmp/test.xml ".//element[@id='3']" |
| 73 | """ |
| 74 | try: |
| 75 | root = ET.parse(file) |
| 76 | element = root.find(element) |
| 77 | return element.attrib |
| 78 | except AttributeError: |
| 79 | log.error("Unable to find element matching %s", element) |
| 80 | return False |
| 81 | |
| 82 | |
| 83 | def set_attribute(file, element, key, value): |