Most viewed recipes tagged "elementtree"http://code.activestate.com/recipes/tags/elementtree/views/2013-06-16T19:14:58-07:00ActiveState Code RecipesElementTree CDATA support (Python)
2008-10-10T12:29:33-07:00Eli Golovinskyhttp://code.activestate.com/recipes/users/2770692/http://code.activestate.com/recipes/576536-elementtree-cdata-support/
<p style="color: grey">
Python
recipe 576536
by <a href="/recipes/users/2770692/">Eli Golovinsky</a>
(<a href="/recipes/tags/elementtree/">elementtree</a>, <a href="/recipes/tags/xml/">xml</a>).
Revision 2.
</p>
<p>This recipe monkey-patches the ElementTree library to allow correct parsing and generation of CDATA sections.</p>
Arbitrary 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>
XML to PDF book with ElementTree and xtopdf (Python)
2013-06-16T19:14:58-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578561-xml-to-pdf-book-with-elementtree-and-xtopdf/
<p style="color: grey">
Python
recipe 578561
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/ebooks/">ebooks</a>, <a href="/recipes/tags/elementtree/">elementtree</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/publishing/">publishing</a>, <a href="/recipes/tags/xml/">xml</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to create a PDF book from XML text content. It requires my xtopdf toolkit, the ElementTree module (from Python's standard library) and the open source version of the ReportLab toolkit.</p>
<p>Create an XML template file like this:</p>
<p><?xml version="1.0"?>
<book>
<chapter>
Chapter 1 content here.
</chapter></p>
<pre class="prettyprint"><code> <chapter>
Chapter 2 content here.
</chapter>
</code></pre>
<p></book></p>
<p>Then populate the chapter elements with the text of each of the chapters of your book, as text. Call that file, your_book.xml, say.</p>
<p>Then run:</p>
<p>python XMLtoPDFBook.py your_book.xml your_book.pdf</p>
<p>Now the contents of your book will be in your_book.pdf</p>
<p>More details and the full code here:</p>
<p><a href="http://jugad2.blogspot.in/2013/06/create-pdf-books-with-xmltopdfbook.html" rel="nofollow">http://jugad2.blogspot.in/2013/06/create-pdf-books-with-xmltopdfbook.html</a></p>
<ul>
<li>Vasudev Ram
<a href="http://dancingbison.com" rel="nofollow">dancingbison.com</a></li>
</ul>