Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alek-dr/xmlobj
xmlobj is simple utility to map xml file to python object
https://github.com/alek-dr/xmlobj
xml xml-document xml-parser
Last synced: about 4 hours ago
JSON representation
xmlobj is simple utility to map xml file to python object
- Host: GitHub
- URL: https://github.com/alek-dr/xmlobj
- Owner: Alek-dr
- Created: 2023-08-09T11:18:45.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-04T07:19:14.000Z (11 months ago)
- Last Synced: 2024-10-12T04:56:26.836Z (27 days ago)
- Topics: xml, xml-document, xml-parser
- Language: Python
- Homepage:
- Size: 164 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Description
xmlobj is simple utility to map xml file to python objectxmlobj also allows you to add functionality to mapped object by adding mixin class
### A Simple Example
```
from pathlib import Pathfrom 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 imageif __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 ETfrom 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:
```
Empire Burlesque
Bob Dylan
USA
```
Output:
```Empire Burlesque
Bob Dylan
USA```
* Attribute propertiesOriginal:
```
Gambardella, Matthew
XML Developer's Guide
Computer
44.95
2000-10-01
An in-depth look at creating applications
with XML.
```
Output:
```bk101
Gambardella, Matthew
XML Developer's Guide
Computer
44.95
2000-10-01
An in-depth look at creating applications
with XML.```
### Installation
```
pip install xmlobj
```