# This software may be freely redistributed under the terms of the GNU
# general public license version 2.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION='''
---
module: xml
short_description: Manage bits and pieces of XML files or strings
description:
- A CRUD-like interface to managing bits of XML flies. You might also be interested in a brief tutorial, U(http://www.w3schools.com/xpath/). Note that module this does not handle complicated xpath expressions. So limit xpath selectors to simple expressions.
version_added: "1.0"
options:
file:
description:
- Path to the file to operate on. File must exist ahead of time.
required: true unless xmlstring is given
default: null
choices: []
xmlstring:
description:
- A string containing XML on which to operate.
required: true unless file is given
default: null
choices: []
xpath:
description:
- A valid XPath expression describing the item(s) you want to manipulate. Operates on the document root, C(/), by default.
required: false
default: /
choices: []
namespaces:
description:
- The namespace prefix:uri mapping for the XPath expression. Needs to be a *map*, not a list of items.
required: false
default: null
choices: []
ensure:
description:
- Set or remove an xpath selection (node(s), attribute(s))
required: false
default: present
choices:
- "absent"
- "present"
value:
description:
- Desired state of the selected attribute. Either a string, or to unset a value, the Python C(None) keyword (YAML Equivalent, C(null)).
required: false
default: Elements default to no value (but present). Attributes default to an empty string.
choices: []
add_children:
description:
- 'Add additional child-element(s) to a selected element. Child elements must be given in a list and each item may be either a string (ex: C(children=ansible) to add an empty C(<ansible/>) child element), or a hash where the key is an element name and the value is the element value.'
required: false
default: null
choices: []
set_children:
description:
- 'Set the the child-element(s) of a selected element. Removes any existing children. Child elements must be specified as in C(add_children).'
required: false
default: null
choices: []
count:
description:
- "Search for a given C(xpath) and provide the count of any matches"
required: false
default: null
choices: []
print_match:
description:
- "Search for a given C(xpath) and print out any matches"
required: false
default: null
choices: []
pretty_print:
description:
- "Pretty print output XML"
required: false
default: false
choices: []
content:
description:
- "Search for a given C(xpath) and get content"
required: false
default: false
choices:
- "attribute"
- "text"
requirements:
- The remote end must have the Python C(lxml) library installed