Skip to content

Commit e5039ad

Browse files
committed
docs(readme): add API reference for parse()/unparse() kwargs
1 parent 927a025 commit e5039ad

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,51 @@ Lists that are specified under a key in a dictionary use the key as a tag for ea
194194
</line>
195195
```
196196

197+
## API Reference
198+
199+
### xmltodict.parse()
200+
201+
Parse XML input into a Python dictionary.
202+
203+
- `xml_input`: XML input as a string, file-like object, or generator of strings.
204+
- `encoding=None`: Character encoding for the input XML.
205+
- `expat=expat`: XML parser module to use.
206+
- `process_namespaces=False`: Expand XML namespaces if True.
207+
- `namespace_separator=':'`: Separator between namespace URI and local name.
208+
- `disable_entities=True`: Disable entity parsing for security.
209+
- `process_comments=False`: Include XML comments if True. Comments can be preserved when enabled, but by default they are ignored. Multiple top-level comments may not be preserved in exact order.
210+
- `xml_attribs=True`: Include attributes in output dict (with `attr_prefix`).
211+
- `attr_prefix='@'`: Prefix for XML attributes in the dict.
212+
- `cdata_key='#text'`: Key for text content in the dict.
213+
- `force_cdata=False`: Force all text content to be wrapped as CDATA.
214+
- `cdata_separator=''`: Separator string to join multiple text nodes. This joins adjacent text nodes. For example, set to a space to avoid concatenation.
215+
- `postprocessor=None`: Function to modify parsed items.
216+
- `dict_constructor=dict`: Constructor for dictionaries (e.g., dict or OrderedDict).
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.
218+
- `namespaces=None`: Mapping of namespaces to prefixes, or None to keep full URIs.
219+
- `force_list=None`: List of keys or callable to force list values. Useful for elements that may appear once or multiple times. Ensures consistent list output. Can also be a callable for fine-grained control.
220+
- `item_depth=0`: Depth at which to call `item_callback`.
221+
- `item_callback=lambda *args: True`: Function called on items at `item_depth`.
222+
- `comment_key='#comment'`: Key used for XML comments when `process_comments=True`. Only used when `process_comments=True`. Comments can be preserved but multiple top-level comments may not retain order.
223+
224+
### xmltodict.unparse()
225+
226+
Convert a Python dictionary back into XML.
227+
228+
- `input_dict`: Dictionary to convert to XML.
229+
- `output=None`: File-like object to write XML to; returns string if None.
230+
- `encoding='utf-8'`: Encoding of the output XML.
231+
- `full_document=True`: Include XML declaration if True.
232+
- `short_empty_elements=False`: Use short tags for empty elements (`<tag/>`).
233+
- `attr_prefix='@'`: Prefix for dictionary keys representing attributes.
234+
- `cdata_key='#text'`: Key for text content in the dictionary.
235+
- `pretty=False`: Pretty-print the XML output.
236+
- `indent='\t'`: Indentation string for pretty printing.
237+
- `newl='\n'`: Newline character for pretty printing.
238+
- `expand_iter=None`: Tag name to use for items in nested lists (breaks roundtripping).
239+
240+
Note: xmltodict aims to cover the common 90% of cases. It does not preserve every XML nuance (attribute order, mixed content ordering, multiple top-level comments). For exact fidelity, use a full XML library such as lxml.
241+
197242
## Ok, how do I get it?
198243

199244
### Using pypi

0 commit comments

Comments
 (0)