Popular recipes tagged "meta:requires=xml.parsers"http://code.activestate.com/recipes/tags/meta:requires=xml.parsers/2008-08-01T19:24:34-07:00ActiveState Code RecipesArbitrary order attribute writing with ElementTree (Python)
2008-08-01T19:24:34-07:00Orri Ganelhttp://code.activestate.com/recipes/users/2259404/http://code.activestate.com/recipes/576403-arbitrary-order-attribute-writing-with-elementtree/
<p style="color: grey">
Python
recipe 576403
by <a href="/recipes/users/2259404/">Orri Ganel</a>
(<a href="/recipes/tags/attribute/">attribute</a>, <a href="/recipes/tags/element/">element</a>, <a href="/recipes/tags/elementtree/">elementtree</a>, <a href="/recipes/tags/element_tree/">element_tree</a>, <a href="/recipes/tags/etree/">etree</a>, <a href="/recipes/tags/order/">order</a>, <a href="/recipes/tags/sort/">sort</a>, <a href="/recipes/tags/write/">write</a>, <a href="/recipes/tags/writing/">writing</a>, <a href="/recipes/tags/xml/">xml</a>).
Revision 5.
</p>
<p>Modified version of ElementTree with two additional parameters to the write() method: "sortflag" and "sortcmp". "sortflag" defaults to "default", which results in unmodified behavior. "sortcmp" defaults to None, which results in unmodified behavior. See discussion for usage and justification. Changes made begin on line 655.</p>
<p>EDIT: in most cases, unless sortflag happened to be intended for the root, it would be ignored; added sortflag and sortcmp to self._write() call on line 724. Expect another revision in the near future to allow for specifying different orders for different xml tags.</p>
<p>EDIT, the second: Added tag-specific ordering.</p>
Converting XML to dict (for a XPATH-like access syntax) and back to XML (Python)
2007-06-28T03:16:28-07:00Rodrigo Strausshttp://code.activestate.com/recipes/users/2678660/http://code.activestate.com/recipes/522991-converting-xml-to-dict-for-a-xpath-like-access-syn/
<p style="color: grey">
Python
recipe 522991
by <a href="/recipes/users/2678660/">Rodrigo Strauss</a>
(<a href="/recipes/tags/xml/">xml</a>).
Revision 4.
</p>
<p>I really like config files done in Python language itself, using a dictionary declaration. It's cool for programmers, but not so cool for system administrators not used to Python (it's so easy to forget a comma...).
To keep using dictionaries internally providing something more admin friendly, I've done some functions to convert a XML file to Python dictionary (and the reverse as well):</p>
getting properties of an object in webdav/exchange part 2 (Python)
2004-08-05T12:45:06-07:00John Nielsenhttp://code.activestate.com/recipes/users/135654/http://code.activestate.com/recipes/298342-getting-properties-of-an-object-in-webdavexchange-/
<p style="color: grey">
Python
recipe 298342
by <a href="/recipes/users/135654/">John Nielsen</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>Webdav is useful to get information on something in exchange. Often you need to know what you can ask for. Here is a simple recipe to get a list of the attributes available for a specific item.</p>
xmlgettext.py (Python)
2003-07-28T12:29:21-07:00Fritz Cizmarovhttp://code.activestate.com/recipes/users/1031326/http://code.activestate.com/recipes/212728-xmlgettextpy/
<p style="color: grey">
Python
recipe 212728
by <a href="/recipes/users/1031326/">Fritz Cizmarov</a>
(<a href="/recipes/tags/xml/">xml</a>).
</p>
<p>extract the texts from an XML-file and write it into an *.pot</p>
xml2obj (Python)
2002-09-11T21:51:43-07:00John Bairhttp://code.activestate.com/recipes/users/682343/http://code.activestate.com/recipes/149368-xml2obj/
<p style="color: grey">
Python
recipe 149368
by <a href="/recipes/users/682343/">John Bair</a>
(<a href="/recipes/tags/xml/">xml</a>).
</p>
<p>A generic script using expat to convert xml into objects</p>