https://github.com/gisce/libcomxml
Python object XML serialization
https://github.com/gisce/libcomxml
hacktoberfest python serialization xml
Last synced: about 1 year ago
JSON representation
Python object XML serialization
- Host: GitHub
- URL: https://github.com/gisce/libcomxml
- Owner: gisce
- License: gpl-3.0
- Created: 2012-01-18T16:41:49.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2017-10-24T09:49:32.000Z (over 8 years ago)
- Last Synced: 2025-04-12T07:17:22.634Z (about 1 year ago)
- Topics: hacktoberfest, python, serialization, xml
- Language: Python
- Homepage: http://libcomxml.readthedocs.org
- Size: 389 KB
- Stars: 3
- Watchers: 19
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: COPYING
Awesome Lists containing this project
README
=========
libComXML
=========
.. image:: https://travis-ci.org/gisce/libComXML.png?branch=master
:target: https://travis-ci.org/gisce/libComXML
:alt: Build Status
.. image:: https://coveralls.io/repos/github/gisce/libComXML/badge.svg?branch=master
:target: https://coveralls.io/github/gisce/libComXML?branch=master
This library permits XML generation from Python objects
.. code-block:: xml
Empire Burlesque
Bob Dylan
USA
Columbia
10.90
1985
Hide your heart
Bonnie Tyler
UK
CBS Records
9.90
1988
Tupelo Honey
Van Morrison
UK
Polydor
8.20
1971
.. code-block:: python
from libcomxml.core import XmlModel, XmlField
class Cd(XmlModel):
def __init__(self):
self.data = XmlField('CD')
self.title = XmlField('TITLE')
self.artist = XmlField('ARTIST')
self.country = XmlField('COUNTRY')
self.company = XmlField('COMPANY')
self.price = XmlField('PRICE')
self.year = XmlField('YEAR')
super(Cd, self).__init__('CD', 'data')
class Catalog(XmlModel):
def __init__(self):
self.catalog = XmlField('CATALOG')
self.cds = []
super(Catalog, self).__init__('CATALOG', 'catalog')
catalog = Catalog()
cd = Cd()
cd.feed({
'title': 'Empire Burlesque',
'artist': 'Bob Dylan',
'country': 'USA',
'company': 'Columbia',
'price': 10.90,
'year': 1985
})
catalog.cds.append(cd)
cd = Cd()
cd.feed({
'title': 'Hide your hear',
'artist': 'Bonnie Tyler',
'country': 'UK',
'company': 'CBS Records',
'price': 9.90,
'year': 1988
})
catalog.cds.append(cd)
# Also we can add XML String directly as a new element
cd = """
Tupelo Honey
Van Morrison
UK
Polydor
8.20
1971
"""
self.catalog.cds.append(cd)
catalog.build_tree()
print catalog