xmlobj is simple utility to map xml file to python object
Project description
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()
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xmlobj-1.2.0.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file xmlobj-1.2.0.tar.gz
.
File metadata
- Download URL: xmlobj-1.2.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45664034606b457351a208007dc2990a5e4f2c24121ce5871d4760dac049fccb |
|
MD5 | 60fcaa1ec07bd8ff82a460b093f273e6 |
|
BLAKE2b-256 | 519fa44d0a00006974f274ddb94f4dde8b89568ba86dc73f72f7a8ef627338c6 |
File details
Details for the file xmlobj-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: xmlobj-1.2.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1902ca07f9afb4f08ca702555d9972d2ecbec2f695d77e7fbc3a415656816ae2 |
|
MD5 | 93f7b3e464ea7dbb4dcf752d59c0e9b9 |
|
BLAKE2b-256 | c4b38abcb39178f232e4a17f9b1745abf5fce5d506a028e389355ce148b6f84c |