[Kimchi-devel] [PATCH 2/8] Allow updating XML attribute in "xml_item_update"
Aline Manera
alinefm at linux.vnet.ibm.com
Mon Nov 3 16:08:51 UTC 2014
Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>
On 11/02/2014 11:05 PM, Crístian Viana wrote:
> The function "xml_item_update" only updates the content of any given
> tag, filtered by an XPath expression. However, one might want to update
> one of the tag's attributes instead of its content.
>
> Add an optional parameter to "xml_item_update" which sets the attribute
> name to be updated; if not set, the function will behave as before, i.e.
> update the tag's content.
>
> Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
> ---
> src/kimchi/xmlutils/utils.py | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/src/kimchi/xmlutils/utils.py b/src/kimchi/xmlutils/utils.py
> index bfbe0c1..4863bb5 100644
> --- a/src/kimchi/xmlutils/utils.py
> +++ b/src/kimchi/xmlutils/utils.py
> @@ -27,10 +27,13 @@ def xpath_get_text(xml, expr):
> return res
>
>
> -def xml_item_update(xml, xpath, value):
> +def xml_item_update(xml, xpath, value, attr=None):
> root = ET.fromstring(xml)
> item = root.find(xpath)
> - item.text = value
> + if attr is None:
> + item.text = value
> + else:
> + item.set(attr, value)
> return ET.tostring(root, encoding="utf-8")
>
>
More information about the Kimchi-devel
mailing list