Skip to content

Commit b3e2203

Browse files
committed
docs: clarify strip whitespace comment behavior
1 parent 2c0f299 commit b3e2203

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Parse XML input into a Python dictionary.
214214
- `cdata_separator=''`: Separator string to join multiple text nodes. This joins adjacent text nodes. For example, set to a space to avoid concatenation.
215215
- `postprocessor=None`: Function to modify parsed items.
216216
- `dict_constructor=dict`: Constructor for dictionaries (e.g., dict).
217-
- `strip_whitespace=True`: Remove leading/trailing whitespace in text nodes. Default is True; this trims whitespace in text nodes. Set to False to preserve whitespace exactly.
217+
- `strip_whitespace=True`: Remove leading/trailing whitespace in text nodes. Default is True; this trims whitespace in text nodes. Set to False to preserve whitespace exactly. When `process_comments=True`, this same flag also trims comment text; disable `strip_whitespace` if you need to preserve comment indentation or padding.
218218
- `namespaces=None`: Mapping of namespaces to prefixes, or None to keep full URIs.
219219
- `force_list=None`: Force list values for specific elements. Can be a boolean (True/False), a tuple of element names to force lists for, or a callable function that receives (path, key, value) and returns True/False. Useful for elements that may appear once or multiple times to ensure consistent list output.
220220
- `item_depth=0`: Depth at which to call `item_callback`.

xmltodict.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ def parse(xml_input, encoding=None, expat=expat, process_namespaces=False,
329329
'd': '2',
330330
},
331331
}
332+
Comment text is subject to the `strip_whitespace` flag: when it is left
333+
at the default `True`, comments will have leading and trailing
334+
whitespace removed. Disable `strip_whitespace` to keep comment
335+
indentation or padding intact.
332336
"""
333337
handler = _DictSAXHandler(namespace_separator=namespace_separator,
334338
**kwargs)

0 commit comments

Comments
 (0)