Popular recipes tagged "xml"http://code.activestate.com/recipes/tags/xml/2017-02-22T23:00:21-08:00ActiveState Code RecipesXML viewer for Tkinter or XML treeview (Python) 2017-02-22T23:00:21-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580752-xml-viewer-for-tkinter-or-xml-treeview/ <p style="color: grey"> Python recipe 580752 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/browser/">browser</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/treeview/">treeview</a>, <a href="/recipes/tags/viewer/">viewer</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 3. </p> <p>Tk widget to display XML for Python. I use the treeview widget. There is no external dependency.I also added support for autoscrollbars.</p> Convert CSV to XML (Python) 2010-10-11T06:20:19-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577423-convert-csv-to-xml/ <p style="color: grey"> Python recipe 577423 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>Convert CSV to XML.</p> MicroXml: Stand-alone library for basic XML features (C++) 2016-02-18T19:33:07-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/580612-microxml-stand-alone-library-for-basic-xml-feature/ <p style="color: grey"> C++ recipe 580612 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>MicroXml provides stand-alone support for the basic, most-used features of XML -- tags, attributes, and element values. It produces a DOM tree of XML nodes. MicroXml does not support DTDs, CDATAs and other advanced XML features.</p> <p>MicroXml is easy to use and provides easy access to view/navigate its nodes in a debugger.</p> MicroXml: Stand-alone library for basic XML features (Python) 2015-12-04T22:36:56-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579133-microxml-stand-alone-library-for-basic-xml-feature/ <p style="color: grey"> Python recipe 579133 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>MicroXml provides stand-alone support for the basic, most-used features of XML -- tags, attributes, and element values. It produces a DOM tree of XML nodes. It's compatible with Python 2.7 and Python 3. MicroXml does not support DTDs, CDATAs and other advanced XML features.</p> <p>MicroXml is easy to use and easy to view/navigate its nodes in a debugger. It also includes a minimal XPath-like implementation.</p> Python AST to XML (Python) 2015-02-05T20:18:08-08:00Robert Stewarthttp://code.activestate.com/recipes/users/4191612/http://code.activestate.com/recipes/579019-python-ast-to-xml/ <p style="color: grey"> Python recipe 579019 by <a href="/recipes/users/4191612/">Robert Stewart</a> (<a href="/recipes/tags/ast/">ast</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>Convert Python ASTs to XML files for reading in other languages.</p> Objectify of a XML node (Python) 2014-12-05T04:39:51-08:00Thomas Lehmannhttp://code.activestate.com/recipes/users/4174477/http://code.activestate.com/recipes/578976-objectify-of-a-xml-node/ <p style="color: grey"> Python recipe 578976 by <a href="/recipes/users/4174477/">Thomas Lehmann</a> (<a href="/recipes/tags/objectify/">objectify</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>The script allows you to convert a XML node into an object instance that has the XML node attributes as fields with the given values. The values are converted (when possible):</p> <ul> <li>from string to int</li> <li>from string to float</li> <li>or remain as string</li> </ul> <p>You also initially can provide a dictionary of (key,value) to ensure existence of certain fields which might not be provided by the XML node but on the other hand those values might be overwritten by the XML node.</p> <p>Please have a look at the docstring for the example ...</p> Convert Wordpress Export File to multiple html files (Python) 2014-06-15T03:17:19-07:00rrebotohttp://code.activestate.com/recipes/users/4190203/http://code.activestate.com/recipes/578892-convert-wordpress-export-file-to-multiple-html-fil/ <p style="color: grey"> Python recipe 578892 by <a href="/recipes/users/4190203/">rreboto</a> (<a href="/recipes/tags/xml/">xml</a>). </p> <p>Converts Wordpress Export Files (XML) to multiple html files and optionally uses tags and authors to create a directory structure.</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>&lt;?xml version="1.0"?&gt; &lt;book&gt; &lt;chapter&gt; Chapter 1 content here. &lt;/chapter&gt;</p> <pre class="prettyprint"><code> &lt;chapter&gt; Chapter 2 content here. &lt;/chapter&gt; </code></pre> <p>&lt;/book&gt;</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> Python AST to XML (Python) 2013-08-07T00:42:35-07:00Ryan Gonzalezhttp://code.activestate.com/recipes/users/4187447/http://code.activestate.com/recipes/578625-python-ast-to-xml/ <p style="color: grey"> Python recipe 578625 by <a href="/recipes/users/4187447/">Ryan Gonzalez</a> (<a href="/recipes/tags/ast/">ast</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>Converts Python ASTs to XML files for reading in other languages.</p> Validate XML with schemaLocation (Python) 2013-03-28T10:24:55-07:00Mathias Loeschhttp://code.activestate.com/recipes/users/4185910/http://code.activestate.com/recipes/578503-validate-xml-with-schemalocation/ <p style="color: grey"> Python recipe 578503 by <a href="/recipes/users/4185910/">Mathias Loesch</a> (<a href="/recipes/tags/schema/">schema</a>, <a href="/recipes/tags/schemalocation/">schemalocation</a>, <a href="/recipes/tags/validation/">validation</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 3. </p> <p>Addresses problems described at:</p> <p><a href="http://stackoverflow.com/questions/2979824/in-document-schema-declarations-and-lxml" rel="nofollow">http://stackoverflow.com/questions/2979824/in-document-schema-declarations-and-lxml</a> <a href="https://mailman-mail5.webfaction.com/pipermail/lxml/2011-September/006153.html" rel="nofollow">https://mailman-mail5.webfaction.com/pipermail/lxml/2011-September/006153.html</a></p> Reading XML into dict-like object (Python) 2013-03-14T18:50:07-07:00Lucas Oliveirahttp://code.activestate.com/recipes/users/4185629/http://code.activestate.com/recipes/578492-reading-xml-into-dict-like-object/ <p style="color: grey"> Python recipe 578492 by <a href="/recipes/users/4185629/">Lucas Oliveira</a> (<a href="/recipes/tags/attributes/">attributes</a>, <a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 4. </p> <ul> <li>Load XML, tree or root</li> <li>Make its children available through __getitem__</li> <li>Make its attributes available through __getattr__</li> <li>If child is requested, return an instance created with child as new root</li> <li>Make its text accessible through __getattr__, using attribute "text"</li> </ul> Convert CSV to XML (Python) 2012-12-17T16:16:04-08:00Tom Wissinghttp://code.activestate.com/recipes/users/4184629/http://code.activestate.com/recipes/578384-convert-csv-to-xml/ <p style="color: grey"> Python recipe 578384 by <a href="/recipes/users/4184629/">Tom Wissing</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>Convert CSV to XML.</p> LXML Etree XML Object to basic Python {dict+lists} (Python) 2012-08-20T07:06:54-07:00Luis Martin Gilhttp://code.activestate.com/recipes/users/4183220/http://code.activestate.com/recipes/578244-lxml-etree-xml-object-to-basic-python-dictlists/ <p style="color: grey"> Python recipe 578244 by <a href="/recipes/users/4183220/">Luis Martin Gil</a> (<a href="/recipes/tags/lxml/">lxml</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>Convert an Etree XML structure into a Python dict+list</p> Nested contexts -- a chain of mapping objects (Python) 2010-10-25T02:13:37-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of-mapping-objects/ <p style="color: grey"> Python recipe 577434 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/ast/">ast</a>, <a href="/recipes/tags/chained/">chained</a>, <a href="/recipes/tags/compiler/">compiler</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/nested/">nested</a>, <a href="/recipes/tags/nonlocal/">nonlocal</a>, <a href="/recipes/tags/scopes/">scopes</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>Easy to use chain of dictionaries for crafting nested scopes or for a tree of scopes. Useful for analyzing AST nodes, XML nodes or other structures with multiple scopes. Can emulate various chaining styles including static/lexical scoping, dynamic scoping and Python's own globals(), locals(), nested scopes, and writeable nonlocals. Can also model Python's inheritance chains: instance dictionary, class dictionary, and base classes.</p> XML To Python object(next generation) with real life example: fetching US Treasure Curve (Python) 2012-02-14T01:24:28-08:00Boris Katshttp://code.activestate.com/recipes/users/4180778/http://code.activestate.com/recipes/578032-xml-to-python-objectnext-generation-with-real-life/ <p style="color: grey"> Python recipe 578032 by <a href="/recipes/users/4180778/">Boris Kats</a> (<a href="/recipes/tags/object/">object</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 11. </p> <p>This middle sized python class will populate himself from any xml with reasonable restrictions.</p> XML as Dictionary (Python) 2012-01-17T18:10:29-08:00Vikram Baghelhttp://code.activestate.com/recipes/users/4180561/http://code.activestate.com/recipes/578017-xml-as-dictionary/ <p style="color: grey"> Python recipe 578017 by <a href="/recipes/users/4180561/">Vikram Baghel</a> (<a href="/recipes/tags/xml/">xml</a>). </p> <p>I use this for configuration. I hadn't intended to put it up anywhere, but there have been a couple discussions lately about converting XML to python dicts, so I feel obligated to share another approach, one that is based on Fredrik Lundh's ElementTree.</p> Syntactic sugar to create XHTML hierarchies with ElementTree (Python) 2012-01-18T22:15:58-08:00Alain Mellanhttp://code.activestate.com/recipes/users/4065697/http://code.activestate.com/recipes/578020-syntactic-sugar-to-create-xhtml-hierarchies-with-e/ <p style="color: grey"> Python recipe 578020 by <a href="/recipes/users/4065697/">Alain Mellan</a> (<a href="/recipes/tags/xml/">xml</a>). </p> <p>Simplify the code when creating XHTML or XML hierarchies with ElementTree.</p> <p>Usually, I have code like this:</p> <pre class="prettyprint"><code>table = ET.SubElement(body, 'table') table.attrib['border'] = '1' tr = ET.SubElement(table, 'tr') ET.SubElement(tr, 'td').text = 'some text' </code></pre> <p>Using Python's __getattr__ and partial function evaluation allows to create an object that will yield a much simplified syntax.</p> Convert a nested Python data structure to XML (Python) 2011-10-17T12:48:59-07:00Graham Poulterhttp://code.activestate.com/recipes/users/4172291/http://code.activestate.com/recipes/577882-convert-a-nested-python-data-structure-to-xml/ <p style="color: grey"> Python recipe 577882 by <a href="/recipes/users/4172291/">Graham Poulter</a> (<a href="/recipes/tags/serialize/">serialize</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>Uses lxml.etree to convert a Python object consisting of nested dicts, tuples, lists, strings and string-convertable objects into a very basic no-attributes, untyped dialect of XML in which elements are named after dictionary keys, and "&lt;i&gt;" is the element for anonymous list and tuple items.</p> <p>Does not support: encoding or decoding of strings, invalid floating point values, detection of circular references.</p> dict2xml (Python) 2011-07-19T12:32:57-07:00nuggetierhttp://code.activestate.com/recipes/users/4178225/http://code.activestate.com/recipes/577739-dict2xml/ <p style="color: grey"> Python recipe 577739 by <a href="/recipes/users/4178225/">nuggetier</a> (<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 4. </p> <p>convert dictionary / list structures into xml structure</p> xml to python dictionary and back (Python) 2012-10-24T00:44:30-07:00kris kvilekvalhttp://code.activestate.com/recipes/users/4178118/http://code.activestate.com/recipes/577722-xml-to-python-dictionary-and-back/ <p style="color: grey"> Python recipe 577722 by <a href="/recipes/users/4178118/">kris kvilekval</a> (<a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/mapping/">mapping</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>Simple mapping of XML to python dictionary based on Perl XML::Simple</p>