Outils pour utilisateurs

Outils du site


tech:xml_xpath_parse

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
tech:xml_xpath_parse [2025/03/24 15:06] – créée - modification externe 127.0.0.1tech:xml_xpath_parse [2026/05/29 13:13] (Version actuelle) Jean-Baptiste
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 +{{tag>Brouillon}}
 +
 +# XML xpath parse
 +
 +Il existe deux langages de requêtes XML : **XPath** et **XQuery**. 
 +
 +Voir aussi :
 +* xml_grep (xml-twig-tools), xmldiff, [[https://en.wikipedia.org/wiki/XMLStarlet|xmlstarlet]]
 +
 +
 +
 +## Lint
 +
 +~~~bash
 +xmllint --noout fic.xml
 +~~~
 +
 +
 +## xpath
 +
 +~~~bash
 +virsh dumpxml VM1 |xpath -q -e "/domain/devices/disk[@type='file']/source/@file[1]"
 +~~~
 +
 +
 +## Ansible
 +
 +### Exemple
 +
 +`/etc/ImageMagick-6/policy.xml`
 +~~~xml
 +<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
 +
 +`/etc/ImageMagick-6/policy.xml
 +~~~xml
 +<policymap>
 +  <policy domain="resource" name="time" value="5"/>
 +</policymap>
 +~~~
 +
 +Conf Ansible
 +
 +~~~yaml
 +- 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"
 +~~~
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki