MCPcopy Create free account
hub / github.com/saltstack/salt / set_value

Function set_value

salt/modules/xml.py:43–61  ·  view source on GitHub ↗

Sets the value of the matched xpath element CLI Example: .. code-block:: bash salt '*' xml.set_value /tmp/test.xml ".//element" "new value"

(file, element, value)

Source from the content-addressed store, hash-verified

41
42
43def set_value(file, element, value):
44 """
45 Sets the value of the matched xpath element
46
47 CLI Example:
48
49 .. code-block:: bash
50
51 salt '*' xml.set_value /tmp/test.xml ".//element" "new value"
52 """
53 try:
54 root = ET.parse(file)
55 relement = root.find(element)
56 except AttributeError:
57 log.error("Unable to find element matching %s", element)
58 return False
59 relement.text = str(value)
60 root.write(file)
61 return True
62
63
64def get_attribute(file, element):

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected