mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Add option to control CDATA tags stripping (#42689)
* Add option to control CDATA tags stripping * Fix remaining issues before merging. * Add missing trailing dot.
This commit is contained in:
parent
fa8de0c384
commit
a97618b486
1 changed files with 10 additions and 1 deletions
|
@ -106,6 +106,13 @@ options:
|
||||||
the original file back if you somehow clobbered it incorrectly.
|
the original file back if you somehow clobbered it incorrectly.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
|
strip_cdata_tags:
|
||||||
|
description:
|
||||||
|
- Remove CDATA tags surrounding text values.
|
||||||
|
- Note that this might break your XML file if text values contain characters that could be interpreted as XML.
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
|
version_added: '2.7'
|
||||||
requirements:
|
requirements:
|
||||||
- lxml >= 2.3.0
|
- lxml >= 2.3.0
|
||||||
notes:
|
notes:
|
||||||
|
@ -732,6 +739,7 @@ def main():
|
||||||
content=dict(type='str', choices=['attribute', 'text']),
|
content=dict(type='str', choices=['attribute', 'text']),
|
||||||
input_type=dict(type='str', default='yaml', choices=['xml', 'yaml']),
|
input_type=dict(type='str', default='yaml', choices=['xml', 'yaml']),
|
||||||
backup=dict(type='bool', default=False),
|
backup=dict(type='bool', default=False),
|
||||||
|
strip_cdata_tags=dict(type='bool', default=False),
|
||||||
),
|
),
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
# TODO: Implement this as soon as #28662 (required_by functionality) is merged
|
# TODO: Implement this as soon as #28662 (required_by functionality) is merged
|
||||||
|
@ -772,6 +780,7 @@ def main():
|
||||||
print_match = module.params['print_match']
|
print_match = module.params['print_match']
|
||||||
count = module.params['count']
|
count = module.params['count']
|
||||||
backup = module.params['backup']
|
backup = module.params['backup']
|
||||||
|
strip_cdata_tags = module.params['strip_cdata_tags']
|
||||||
|
|
||||||
# Check if we have lxml 2.3.0 or newer installed
|
# Check if we have lxml 2.3.0 or newer installed
|
||||||
if not HAS_LXML:
|
if not HAS_LXML:
|
||||||
|
@ -800,7 +809,7 @@ def main():
|
||||||
|
|
||||||
# Try to parse in the target XML file
|
# Try to parse in the target XML file
|
||||||
try:
|
try:
|
||||||
parser = etree.XMLParser(remove_blank_text=pretty_print)
|
parser = etree.XMLParser(remove_blank_text=pretty_print, strip_cdata=strip_cdata_tags)
|
||||||
doc = etree.parse(infile, parser)
|
doc = etree.parse(infile, parser)
|
||||||
except etree.XMLSyntaxError as e:
|
except etree.XMLSyntaxError as e:
|
||||||
module.fail_json(msg="Error while parsing document: %s (%s)" % (xml_file or 'xml_string', e))
|
module.fail_json(msg="Error while parsing document: %s (%s)" % (xml_file or 'xml_string', e))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue