MCPcopy
hub / github.com/saltstack/salt / set_attribute

Function set_attribute

salt/modules/xml.py:83–101  ·  view source on GitHub ↗

Set the requested attribute key and value for matched xpath element. CLI Example: .. code-block:: bash salt '*' xml.set_attribute /tmp/test.xml ".//element[@id='3']" editedby "gal"

(file, element, key, value)

Source from the content-addressed store, hash-verified

81
82
83def set_attribute(file, element, key, value):
84 """
85 Set the requested attribute key and value for matched xpath element.
86
87 CLI Example:
88
89 .. code-block:: bash
90
91 salt '*' xml.set_attribute /tmp/test.xml ".//element[@id='3']" editedby "gal"
92 """
93 try:
94 root = ET.parse(file)
95 element = root.find(element)
96 except AttributeError:
97 log.error("Unable to find element matching %s", element)
98 return False
99 element.set(key, str(value))
100 root.write(file)
101 return True

Callers

nothing calls this directly

Calls 5

findMethod · 0.80
parseMethod · 0.45
errorMethod · 0.45
setMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected