[Chicago] modifying xml ?

Ken Schutte kenschutte at gmail.com
Thu Oct 14 23:10:00 CEST 2010


If you get the node, you should just be able to set .text on it, I believe,

node = root.find('aaa/bbb')
node.text = "foo"

Note this just sets the text inside the node, such as <bbb>foo</bbb>.
To add nodes, use node.append(newnode), etc.

Also, if you're looking for a single node in a large xml file, you
might want to look into SAX (e.g. lxml.sax).  Unlike DOM-style
approaches, SAX libraries do not load and parse the entire document -
they just scan it sequentially for what you are interested in.

Ken


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
>


More information about the Chicago mailing list