XML xpath parse

Il existe deux langages de requêtes XML : XPath et XQuery.

Voir aussi :

xml_grep (xml-twig-tools), xmldiff, xmlstarlet

Lint

xmllint --noout fic.xml

xpath

virsh dumpxml VM1 |xpath -q -e "/domain/devices/disk[@type='file']/source/@file[1]"

Ansible

Exemple

<policymap> <policy domain="resource" name="memory" value="256MiB"/> <policy domain="resource" name="map" value="512MiB"/> <policy domain="resource" name="width" value="16KP"/> <policy domain="resource" name="height" value="16KP"/> <policy domain="resource" name="area" value="128MB"/> <policy domain="resource" name="disk" value="1GiB"/> <!-- <policy domain="resource" name="time" value="3600"/> --> <policy domain="delegate" rights="none" pattern="URL" /> <policy domain="delegate" rights="none" pattern="HTTPS" /> <policy domain="delegate" rights="none" pattern="HTTP" /> <policy domain="path" rights="none" pattern="@*"/> </policymap>

Nous voulons ajouter

<policymap> <policy domain="resource" name="time" value="5"/> </policymap>

Conf Ansible

- name: install deps for ansible xml module apt: name='{{ packages }}' vars: packages: - python-lxml # For Ansible xml - python3-lxml # For Ansible xml - name: /etc/ImageMagick-6/policy.xml - change timeout xml: path: /tmp/policy.xml xpath: /policymap/policy[@domain='resource' and @name='time'] attribute: value value: "5"