Description
xmlobj is simple utility to map xml file to python object
xmlobj also allows you to add functionality to mapped object by adding mixin class
A Simple Example
from pathlib import Path
from PIL import Image, ImageDraw
from xmlobj import get_xml_obj
class DrawBoxesMixin:
def draw_box(self, image) -> Image.Image:
p1 = (self.object.bndbox.xmin, self.object.bndbox.ymin)
p2 = (self.object.bndbox.xmax, self.object.bndbox.ymax)
img_draw = ImageDraw.Draw(image)
img_draw.text(p1, self.object.name, align="left")
img_draw.rectangle([p1, p2])
return image
if __name__ == "__main__":
pascal_annotation = Path("samples/000027.xml")
img_file = "samples/000027.jpg"
img = Image.open(img_file)
obj = get_xml_obj(pascal_annotation, mixin_clsasses=[DrawBoxesMixin])
rendered_img = obj.draw_box(img.copy())
rendered_img.show()
Save xml
import xml.etree.cElementTree as ET
from xmlobj import get_xml_obj
if __name__ == "__main__":
obj = get_xml_obj("samples/books.xml")
root = obj.to_xml()
tree = ET.ElementTree(root)
ET.indent(tree, space="\t", level=0)
tree.write("my_xml_books.xml")
Limitations
- Tag lowercase
Original:
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
</CD>
Output:
<cd>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
</cd>
- Attribute properties
Original:
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.
</description>
</book>
Output:
<book>
<id>bk101</id>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
Installation
pip install xmlobj
Metadata
Release files for xmlobj 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xmlobj-1.2.2-py3-none-any.whl | Python 3 | none | any | Details for xmlobj-1.2.2-py3-none-any.whl |
Release files / xmlobj-1.2.2-py3-none-any.whl
| Download URL | xmlobj-1.2.2-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18bcccfc7d77016bec5ce34310a7eb5d25c02e6a61d5392c3bef61f32855b16a
|
|
BLAKE2b-256 checksum How to use checksums |
e62b6fe5cc70c7433a03b36cc21d3eb16d5a3afed897a66da11a6293885a1418
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for xmlobj 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.