You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,6 +194,51 @@ Lists that are specified under a key in a dictionary use the key as a tag for ea
194
194
</line>
195
195
```
196
196
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.
0 commit comments