xml_from_seq
Generate XML from a Python data structure.
Examples
The XML() function renders a Python list or tuple to an XML element. The first item is the
element name, the second item – if it's a dict – is the attributes, and the rest of the items
are either text or nested elements.
from xml_from_seq import XML
item = ['item', {'attr1': 123, 'attr2': 'other value'}, 'This is the content of the item.']
assert XML(item) == '<item attr1="123" attr2="other value">This is the content of the item.</item>'
item = [
'item',
'This is some content of the item.'
['sub', 'This is the content of a subelement.']
]
print(XML(item))
<item>
This is some content of the item.
<sub>
This is the content of a subelement.
</sub>
</item>
If an element is False or None it will be omitted. If a element's name is None its contents will
appear in its place. If an attribute's value is None it will be omitted.
If an element's name is a list or tuple, it will be inserted into the XML as-is – so you can include already-rendered XML by double-bracketing it:
print(XML([['<foo>123</foo>']]))
<foo>123</foo>
If an element's tag name is xml_from_seq.CDATA, that element's content will be rendered unescaped
in a <![CDATA[...]]> section.
Indentation and line breaks
If the first item in an element (not counting an attribute dict) is xml_from_seq.INLINE, that
element's contents won't be indented on separate lines from the element's start and end tags.
from xml_from_seq import INLINE, XML
item = [
'item',
'This is some content of the item.'
['sub', INLINE, 'This is the content of a subelement.']
]
print(XML(item))
<item>
This is some content of the item.
<sub>This is the content of a subelement.</sub>
</item>
You can pass an integer indent parameter to the XML() function to indent the output XML by
that many tabs.
Metadata
Release files for xml-from-seq 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xml_from_seq-0.3.3.tar.gz | 3.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xml_from_seq-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.9 kB
Release files / xml_from_seq-0.3.3.tar.gz
| Download URL | xml_from_seq-0.3.3.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3fb7ddb1a4d368506c49e5f3cce497f5718b47ab6e3c3f624fee8996fb07e5f
|
|
BLAKE2b-256 checksum How to use checksums |
72feaadaf4f4bc0fc683957fab9f06265204e607107cf6cdcecfe0ce4f964c6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.19
|
Release files / xml_from_seq-0.3.3-py3-none-any.whl
| Download URL | xml_from_seq-0.3.3-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
945543db6760f57a5ddca85bd1e540e5a7c2b4b5393713d4fa1084d79cd9935e
|
|
BLAKE2b-256 checksum How to use checksums |
28791258a9b802c7e7bb18f71d4a6248f38c2f9c368db57c42cc109519454113
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.19
|