I did a little research on this, but really could not come up with anything useful. I need to not just parse and read, but actually manipulate XML documents in python, just as JavaScript is able to manipulate HTML documents.
Let me give you an example. I have the following XML document:
<library> <book id=123> <title>Intro to XML</title> <author>John Smith</author> <year>1996</year> </book> <book id=456> <title>XML 101</title> <author>Bill Jones</author> <year>2000</year> </book> <book id=789> <title>This Book is Unrelated to XML</title> <author>Justin Tyme</author> <year>2006</year> </book> </library>
I need a way to extract an element, either using XPath or using the pythonic method, as described here , but I also need to be able to manipulate the document, for example, below:
>>>xml.getElement('id=123').title="Intro to XML v2" >>>xml.getElement('id=123').year="1998"
If anyone knows about such a tool in Python, please let me know. Thanks!
source share