Thats why I finally pushed myself to develop my own manipulation tool. I think this module is more object-oriented than xml.etree and developer friendly at the same time. "Easyxml" is currently under construction and contains only basic XML generator:
Above will produce following output:
I've got hope that this will be useful not only for me. I'll try to update this project as often as it is possible.
- generating XML document,
- setting basic properties ("version", "encodings").
- creating XML element,
- adding attributes,
- adding sub-elements,
- generating XML document as a string (indentation and separation can be modified),
- writing XML document to file, PIPE and STDOUT.
Things that will be done in the future:
- removing pointed element,
- searching element with "xpath",
- removing elements,
- reorganizing elements order,
- parsing a XML documents,
- refactoring.
Here is an example of use:
from easyxml import XMLDocument, XMLElement
document = XMLDocument(root='address_book', encoding='UTF8')
usr1 = XMLElement(name='user', attributes={'firstname': 'Wiktor', 'lastname': 'Wrutek'})
usr1_addr = XMLElement(name='addres')
usr1_street = XMLElement(name='street', body='Dubois')
usr1_number = XMLElement(name='number', body='48')
# add street and home number as an sub-element of address
usr1_addr.add_element([usr1_street, usr1_number])
# add address as an sub-element of user
usr1.add_element(usr1_addr)
# append elements to document
# currently there is no special method to do this
document.elements.append(usr1)
# indentation set on 4 spaces
print document.string(indent=' ')
Above will produce following output:
<?xml version="0.1" encoding="UTF8"?>
<address_book>
<user lastname="'Wrutek'" firstname="'Wiktor'">
<addres>
<street>
Dubois
</street>
<number>
48
</number>
</addres>
</user>
</address_book>
I've got hope that this will be useful not only for me. I'll try to update this project as often as it is possible.