Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A module to manage various properties of XML documents

License

NotificationsYou must be signed in to change notification settings

cmprescott/ansible-xml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

ansible-xml

Ansible module for manipulating bits and pieces of XML files and strings. This module is currently in devel version ofAnsible. It should be released as part of Ansible 2.4.0 inMid-September. As a consequence, all the issues should be reported toansible.

Installation

Notes

  • Original module created by@github_rhinception.
  • On 2015-05-05,@tbielawa transferred the project over to@cmprescott to resolveissue #16.
  • On 2017-08-08, this module was merged upstream intoAnsible.
  • This software is available under the terms of the GPLv3 license.
  • Hi there, we have unit tests!

What is XPath?

"XPath uses path expressions to select nodes or node-sets in an XMLdocument. The node is selected by following a path or steps."

Basically, it's a syntax which allows you to select a specific, orcollection, of elements or attributes in an XML file.

Learn more at the Mozilla Developer Network

Unittests

Also included in this repository areUnittests. Reference these, in addition to theTravis-CI configuration, if you need some more examples.

Examples

Given:

<?xml version='1.0' encoding='UTF-8'?><businesstype="bar">    <name>Tasty Beverage Co.</name>    <beers>        <beer>Rochefort 10</beer>        <beer>St. Bernardus Abbot 12</beer>        <beer>Schlitz</beer>    </beers>    <ratingsubjective="true">10</rating>    <website>        <mobilefriendly />        <address>http://tastybeverageco.com</address>    </website></business>

Remove thesubjective attribute of the rating element:

xml:path:/foo/bar.xmlxpath:/business/rating/@subjectivestate:absent

Set the rating to11

xml:path:/foo/bar.xmlxpath:/business/ratingvalue:11

Get count of beers nodes

xml:path:/foo/bar.xmlxpath:/business/beers/beercount:yesregister:hitsdebug:var:hits.count

Add aphonenumber element to thebusiness element Implicitmkdir -p behavior where applicable (parent xml nodes createdautomatically)

xml:path:/foo/bar.xmlxpath:/business/phonenumbervalue:555-555-1234

Add several more beers to the beers element, assuming avars.yamlfile with:

new_beers:    -beer:"Old Rasputin"    -beer:"Old Motor Oil"    -beer:"Old Curmudgeon"

Then the playbook syntax would look like this:

xml:path:/foo/bar.xmlxpath:/business/beersadd_children:'{{ new_beers }}'

The same, but do it inline

xml:path:/foo/bar.xmlxpath:/business/beersadd_children:      -beer:"Old Rasputin"      -beer:"Old Motor Oil"      -beer:"Old Curmudgeon"

Add avalidxhtml element to thewebsite element. Note thatstate ispresent by default, andvalue defaults tonull for elements. The result is something like<website><validxhtml />...</website>

xml:path:/foo/bar.xmlxpath:/business/website/validxhtml

Add an emptyvalidatedon attribute to thevalidxhtmlelement. This actually makes the last example redundant because of theimplicit parent-node creation behavior. The result is something like<website><validxhtml validatedon='' />...</website>

xml:path:/foo/bar.xmlxpath:/business/website/validxhtml/@validatedon

(1/2) Remove all children from the website element:

xml:path:/foo/bar.xmlxpath:/business/website/*state:absent

(2/2) Remove all children from the website element:

xml:path:/foo/bar.xmlxpath:/business/websitechildren:[]

Question? If You have<beers><child01 /><child02 /></beers>

What happens if you say:

xml:path:/foo/bar.xmlxpath:/beers

value defaults to an element, so then this would erase thechildren elements.


[8]ページ先頭

©2009-2025 Movatter.jp