xmlobj


Namexmlobj JSON
Version 1.2.2 PyPI version JSON
download
home_page
Summaryxmlobj is simple utility to map xml file to python object
upload_time2023-12-03 08:36:16
maintainer
docs_urlNone
authorAlexander Barmin
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ### 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
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "xmlobj",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Alexander Barmin",
    "author_email": "Alexander Barmin <barmin1@mail.ru>",
    "download_url": "",
    "platform": null,
    "description": "### Description\nxmlobj is simple utility to map xml file to python object\n\nxmlobj also allows you to add functionality to mapped object by adding mixin class\n\n### A Simple Example\n```\nfrom pathlib import Path\n\nfrom PIL import Image, ImageDraw\n\nfrom xmlobj import get_xml_obj\n\n\nclass DrawBoxesMixin:\n    def draw_box(self, image) -> Image.Image:\n        p1 = (self.object.bndbox.xmin, self.object.bndbox.ymin)\n        p2 = (self.object.bndbox.xmax, self.object.bndbox.ymax)\n        img_draw = ImageDraw.Draw(image)\n        img_draw.text(p1, self.object.name, align=\"left\")\n        img_draw.rectangle([p1, p2])\n        return image\n\n\nif __name__ == \"__main__\":\n    pascal_annotation = Path(\"samples/000027.xml\")\n    img_file = \"samples/000027.jpg\"\n    img = Image.open(img_file)\n    obj = get_xml_obj(pascal_annotation, mixin_clsasses=[DrawBoxesMixin])\n    rendered_img = obj.draw_box(img.copy())\n    rendered_img.show()\n\n```\n\n\n### Save xml\n```\nimport xml.etree.cElementTree as ET\n\nfrom xmlobj import get_xml_obj\n\nif __name__ == \"__main__\":\n    obj = get_xml_obj(\"samples/books.xml\")\n    root = obj.to_xml()\n    tree = ET.ElementTree(root)\n    ET.indent(tree, space=\"\\t\", level=0)\n    tree.write(\"my_xml_books.xml\")\n```\n\n### Limitations\n\n* Tag lowercase  \n\nOriginal:\n```\n  <CD>\n    <TITLE>Empire Burlesque</TITLE>\n    <ARTIST>Bob Dylan</ARTIST>\n    <COUNTRY>USA</COUNTRY>\n  </CD>\n```\nOutput:\n```\n<cd>\n    <TITLE>Empire Burlesque</TITLE>\n    <ARTIST>Bob Dylan</ARTIST>\n    <COUNTRY>USA</COUNTRY>\n</cd>\n```\n* Attribute properties\n\nOriginal:\n```\n <book id=\"bk101\">\n        <author>Gambardella, Matthew</author>\n        <title>XML Developer's Guide</title>\n        <genre>Computer</genre>\n        <price>44.95</price>\n        <publish_date>2000-10-01</publish_date>\n        <description>An in-depth look at creating applications\n            with XML.\n        </description>\n    </book>\n```\nOutput:\n```\n<book>\n    <id>bk101</id>\n    <author>Gambardella, Matthew</author>\n    <title>XML Developer's Guide</title>\n    <genre>Computer</genre>\n    <price>44.95</price>\n    <publish_date>2000-10-01</publish_date>\n    <description>An in-depth look at creating applications\n        with XML.</description>\n</book>\n```\n\n### Installation\n```\npip install xmlobj\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "xmlobj is simple utility to map xml file to python object",
    "version": "1.2.2",
    "project_urls": {
        "Homepage": "https://github.com/Alek-dr/xmlobj"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e62b6fe5cc70c7433a03b36cc21d3eb16d5a3afed897a66da11a6293885a1418",
                "md5": "1780afc3df3779f8bb1463065df254e5",
                "sha256": "18bcccfc7d77016bec5ce34310a7eb5d25c02e6a61d5392c3bef61f32855b16a"
            },
            "downloads": -1,
            "filename": "xmlobj-1.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1780afc3df3779f8bb1463065df254e5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4644,
            "upload_time": "2023-12-03T08:36:16",
            "upload_time_iso_8601": "2023-12-03T08:36:16.865320Z",
            "url": "https://files.pythonhosted.org/packages/e6/2b/6fe5cc70c7433a03b36cc21d3eb16d5a3afed897a66da11a6293885a1418/xmlobj-1.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-03 08:36:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Alek-dr",
    "github_project": "xmlobj",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "xmlobj"
}
        
Elapsed time: 0.30684s