From: Anthony T. <mai...@gm...> - 2007-11-08 14:25:11
|
F.Y.I.. There has been support for Jython in the ElementTree subversion repository since 2005 in the form of a file named JavaXMLTreeBuilder.py <http://svn.effbot.org/public/stuff/sandbox/elementlib/JavaXMLTreeBuilder.py>. Below is a sample of its explicit use as a parameter with the version 1.2.7 of ElementTree <http://effbot.org/downloads/#elementtree>, by passing a TreeBuilder instance to the ElementTree.parse as the default parser. Of course you can set it as the default parser in ElementTree.py by modifying the DefaultParserAPI line to be: parser_api = default_parser_api = DefaultParserAPI(parser=JavaXMLTreeBuilder()) Regards, Anthony Tarlano ---------------------------- 89> jython Jython 2.2.1 on java1.6.0_03 Type "copyright", "credits" or "license" for more information. >>> from elementtree.ElementTree import ElementTree >>> from elementtree.JavaXMLTreeBuilder import TreeBuilder >>> tree = ElementTree() >>> tree <elementtree.ElementTree.ElementTree instance 1> >>> root = tree.parse('nsexample.xml', TreeBuilder()) >>> for each in root: ... each ... <Element {http://purl.org/dc/elements/1.1/}Description<http://purl.org/dc/elements/1.1/%7DDescription>at 2> <Element { http://purl.org/dc/elements/1.1/}Title<http://purl.org/dc/elements/1.1/%7DTitle>at 3> <Element {http://fourthought.com/timelog}MinIncrement<http://fourthought.com/timelog%7DMinIncrement>at 4> <Element { http://fourthought.com/timelog}InvoiceNumber<http://fourthought.com/timelog%7DInvoiceNumber>at 5> >>> >>> >>> from elementtree.ElementTree import dump >>> dump(tree) <ns0:ClientInfo xmlns:ns0=" http://fourthought.com/timelog"> <ns1:Description xmlns:ns1="http://purl.org/dc/elements/1.1/"> Fourthought, Inc </ns1:Description> <ns1:Title xmlns:ns1="http://purl.org/dc/elements/1.1/"> Management Subcontracting </ns1:Title> <ns0:MinIncrement>0.25</ns0:MinIncrement> <ns0:InvoiceNumber>7777</ns0:InvoiceNumber> </ns0:ClientInfo> >>> |