[Chicago] modifying xml ?

Tim Gebhardt tim at gebhardtcomputing.com
Thu Oct 14 22:47:45 CEST 2010


If you're looking at lxml, then take a look at the 'objectify' api:
http://codespeak.net/lxml/objectify.html

You could make your modifications after objectifying the xml and then just
dump the object back out to xml.

Relevant code sample from the page:

>>> root = objectify.fromstring(
...             "<root><a>5</a><b>11</b><c>true</c><d>hoi</d></root>")
>>> root.a + root.b
16
>>> root.a += root.b
>>> print(root.a)
16


Tim Gebhardt
tim at gebhardtcomputing.com


On Thu, Oct 14, 2010 at 3:16 PM, Lukasz Szybalski <szybalski at gmail.com>wrote:

> I was looking for more of an lxml examples.
>
> Here is how I extract information but how can I update it?
>
> from lxml import etree
> doc = etree.parse (XMLRequest.xml')
> root=doc.getroot()
>
> print
> root.find("InsuranceSvcRq/PersAutoPolicyQuoteInqRq/PersPolicy/PolicyNumber").text
>
> This will give me a text in that node, but how can I update that?
>
> etree.XPath("InsuranceSvcRq/PersAutoPolicyQuoteInqRq/PersPolicy/PolicyNumber")
> =' 123123' doesn't really work?!
>
>
> I'm not an xml expert, but either its hard to find documentation on
> how to do that or I'm looking for the wrong thing?!
>
> Thanks,
> Lucas
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20101014/2d445a47/attachment.html>


More information about the Chicago mailing list