<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PyXB: Python XML Schema Bindings — PyXB 1.2.6 documentation</title> <link rel="stylesheet" href="_static/classic.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: './', VERSION: '1.2.6', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true, SOURCELINK_SUFFIX: '.txt' }; </script> <script type="text/javascript" src="_static/jquery.js"></script> <script type="text/javascript" src="_static/underscore.js"></script> <script type="text/javascript" src="_static/doctools.js"></script> <link rel="index" title="Index" href="genindex.html" /> <link rel="search" title="Search" href="search.html" /> <link rel="next" title="Overview" href="overview.html" /> </head> <body role="document"> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="overview.html" title="Overview" accesskey="N">next</a> |</li> <li class="nav-item nav-item-0"><a href="#">PyXB 1.2.6 documentation</a> »</li> <li style="margin-left: 20px">PyXB hosted on <a href="http://sourceforge.net/projects/pyxb"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=263147&type=9" width="80" height="15" alt="Get PyXB: Python XML Schema Bindings at SourceForge.net. Fast, secure and Free Open Source software downloads"/></a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="pyxb-python-xml-schema-bindings"> <h1>PyXB: Python XML Schema Bindings<a class="headerlink" href="#pyxb-python-xml-schema-bindings" title="Permalink to this headline">¶</a></h1> <p>PyXB (“pixbee”) is a pure <a class="reference external" href="http://www.python.org">Python</a> package that generates Python source code for classes that correspond to data structures defined by <a class="reference external" href="http://www.w3.org/XML/Schema">XMLSchema</a>. The generated classes support bi-directional conversion between <a class="reference external" href="http://www.w3.org/XML/">XML</a> documents and Python objects. In concept it is similar to <a class="reference external" href="http://en.wikipedia.org/wiki/JAXB">JAXB</a> for Java and <a class="reference external" href="http://www.codesynthesis.com/products/xsd/">CodeSynthesis XSD</a> for C++. A <a class="reference internal" href="#thirty-sec-example"><span class="std std-ref">Thirty Second Example</span></a> is at the bottom of this page. Step-by-step examples are in <a class="reference internal" href="userref_index.html#userreference"><span class="std std-ref">User Reference</span></a>.</p> <div class="section" id="getting-help"> <h2>Getting Help<a class="headerlink" href="#getting-help" title="Permalink to this headline">¶</a></h2> <p>PyXB is distributed on <a class="reference external" href="http://sourceforge.net/projects/pyxb">SourceForge</a> and <a class="reference external" href="https://pypi.python.org/pypi/PyXB/">PyPI</a>, but active development has moved to <a class="reference external" href="https://github.com/pabigot/pyxb">Github</a>. Inter-release updates will be available on github on the <a class="reference external" href="https://github.com/pabigot/pyxb/tree/next">next</a> branch of the PyXB repository.</p> <p>For support, consult the <a class="reference external" href="https://sourceforge.net/projects/pyxb/forums/forum/956708">Help Forum</a>, or subscribe to and email the <a class="reference external" href="https://sourceforge.net/mailarchive/forum.php?forum_name=pyxb-users">mailing list</a>.</p> <p>To file a bug report or see the status of defects reported against the current release, visit the <a class="reference external" href="http://github.com/pabigot/pyxb/issues">Github issues page</a>. (Older defects were archived under Trac at SourceForge; the historical data was moved to the <a class="reference external" href="http://sourceforge.net/p/pyxb/tickets/">SF ticket interface</a> when SourceForge stopped supporting hosted applications. Do not attempt to open new issues on SourceForge.)</p> <p>For a history of releases, see <a class="reference internal" href="releases.html#releases"><span class="std std-ref">Release History</span></a>.</p> </div> <div class="section" id="contents"> <h2>Contents<a class="headerlink" href="#contents" title="Permalink to this headline">¶</a></h2> <div class="toctree-wrapper compound"> <ul> <li class="toctree-l1"><a class="reference internal" href="overview.html">Overview</a><ul> <li class="toctree-l2"><a class="reference internal" href="overview_what.html">What Is PyXB?</a></li> <li class="toctree-l2"><a class="reference internal" href="overview_how.html">How to use it</a></li> <li class="toctree-l2"><a class="reference internal" href="bundles.html">Examples of Supported Schema</a></li> <li class="toctree-l2"><a class="reference internal" href="limitations.html">Limitations</a></li> <li class="toctree-l2"><a class="reference internal" href="legal.html">License and Disclaimers</a></li> <li class="toctree-l2"><a class="reference internal" href="vision.html">PyXB Vision</a></li> <li class="toctree-l2"><a class="reference internal" href="related.html">Related Packages</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a><ul> <li class="toctree-l2"><a class="reference internal" href="examples.html#dictionary-aonaware">Dictionary (Aonaware)</a></li> <li class="toctree-l2"><a class="reference internal" href="examples.html#simple-weather-cdyne">Simple Weather (CDyne)</a></li> <li class="toctree-l2"><a class="reference internal" href="examples.html#professional-weather-national-digital-forecast-data">Professional Weather (National Digital Forecast Data)</a></li> <li class="toctree-l2"><a class="reference internal" href="examples.html#television-schedules-tribune-media-services">Television Schedules (Tribune Media Services)</a></li> <li class="toctree-l2"><a class="reference internal" href="examples.html#address-to-latitude-longitude-http-geocoder-us">Address-To-Latitude/Longitude (http://geocoder.us)</a></li> <li class="toctree-l2"><a class="reference internal" href="examples.html#opengis-http-www-opengeospatial-org">OpenGIS (http://www.opengeospatial.org)</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="releases.html">Release History</a><ul> <li class="toctree-l2"><a class="reference internal" href="releases.html#x">1.2.x</a></li> <li class="toctree-l2"><a class="reference internal" href="releases.html#id6">1.1.x</a></li> <li class="toctree-l2"><a class="reference internal" href="releases.html#x-stable">1.0.x (Stable)</a></li> <li class="toctree-l2"><a class="reference internal" href="releases.html#x-beta">0.7.x (Beta)</a></li> <li class="toctree-l2"><a class="reference internal" href="releases.html#id11">0.5.x (Beta)</a></li> <li class="toctree-l2"><a class="reference internal" href="releases.html#id12">0.4.x (Stable)</a></li> <li class="toctree-l2"><a class="reference internal" href="releases.html#id13">0.2.x (Stable)</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="architecture.html">Architecture</a><ul> <li class="toctree-l2"><a class="reference internal" href="arch_namespaces.html">Namespaces</a></li> <li class="toctree-l2"><a class="reference internal" href="arch_component.html">Component Model</a></li> <li class="toctree-l2"><a class="reference internal" href="arch_binding.html">Binding Model</a></li> <li class="toctree-l2"><a class="reference internal" href="arch_content.html">Content Model</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="userref_index.html">User Reference</a><ul> <li class="toctree-l2"><a class="reference internal" href="userref_pyxbgen.html">Generating Binding Classes</a></li> <li class="toctree-l2"><a class="reference internal" href="userref_usebind.html">Using Binding Classes</a></li> <li class="toctree-l2"><a class="reference internal" href="userref_validating.html">Debugging Validation Errors</a></li> <li class="toctree-l2"><a class="reference internal" href="pyxbgen_cli.html"><code class="docutils literal"><span class="pre">pyxbgen</span></code> Command Line Options</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="pyxb.html">pyxb package</a><ul> <li class="toctree-l2"><a class="reference internal" href="pyxb.html#subpackages">subpackages</a></li> <li class="toctree-l2"><a class="reference internal" href="pyxb.html#submodules">Submodules</a></li> <li class="toctree-l2"><a class="reference internal" href="pyxb.html#module-pyxb.exceptions_">pyxb.exceptions_ module</a></li> <li class="toctree-l2"><a class="reference internal" href="pyxb.html#module-pyxb">Module contents</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="maintref.html">Maintainer Reference</a><ul> <li class="toctree-l2"><a class="reference internal" href="maintref.html#git-repository">Git Repository</a></li> <li class="toctree-l2"><a class="reference internal" href="maintref.html#coding-practices">Coding Practices</a></li> </ul> </li> </ul> </div> </div> <div class="section" id="thirty-second-example"> <span id="thirty-sec-example"></span><h2>Thirty Second Example<a class="headerlink" href="#thirty-second-example" title="Permalink to this headline">¶</a></h2> <p>An example of a program using PyXB to interact with a <a class="reference external" href="http://wiki.cdyne.com/wiki/index.php?title=CDYNE_Weather">web service</a> <a class="footnote-reference" href="#id2" id="id1">[*]</a> using an automatically-generated module. First, retrieve the WSDL and generate the bindings:</p> <div class="highlight-default"><div class="highlight"><pre><span></span>llc[566]$ pyxbgen \ --wsdl-location=http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL \ --module=weather \ --write-for-customization Retrieving WSDL from http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL WARNING:pyxb.binding.basis:Unable to convert DOM node {http://www.w3.org/2001/XMLSchema}schema at Weather.asmx?WSDL[4:4] to binding PS urn:uuid:8292a36c-577f-11e4-b592-c8600024e903 WARNING:pyxb.binding.generate:Complex type {http://ws.cdyne.com/WeatherWS/}ArrayOfWeatherDescription renamed to ArrayOfWeatherDescription_ WARNING:pyxb.binding.generate:Complex type {http://ws.cdyne.com/WeatherWS/}ForecastReturn renamed to ForecastReturn_ WARNING:pyxb.binding.generate:Complex type {http://ws.cdyne.com/WeatherWS/}WeatherReturn renamed to WeatherReturn_ Python for http://ws.cdyne.com/WeatherWS/ requires 1 modules </pre></div> </div> <p>Then write a program that uses them:</p> <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">print_function</span> <span class="kn">import</span> <span class="nn">time</span> <span class="kn">from</span> <span class="nn">pyxb.utils.six.moves.urllib</span> <span class="k">import</span> <span class="n">request</span> <span class="k">as</span> <span class="n">urllib_request</span> <span class="kn">import</span> <span class="nn">weather</span> <span class="c1"># Bindings generated by PyXB</span> <span class="kn">import</span> <span class="nn">pyxb.utils.domutils</span> <span class="k">as</span> <span class="nn">domutils</span> <span class="n">uri</span> <span class="o">=</span> <span class="s1">'http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityForecastByZIP?ZIP=55113'</span> <span class="n">xml</span> <span class="o">=</span> <span class="n">urllib_request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">uri</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="n">doc</span> <span class="o">=</span> <span class="n">domutils</span><span class="o">.</span><span class="n">StringToDOM</span><span class="p">(</span><span class="n">xml</span><span class="p">)</span> <span class="n">fc_return</span> <span class="o">=</span> <span class="n">weather</span><span class="o">.</span><span class="n">CreateFromDOM</span><span class="p">(</span><span class="n">doc</span><span class="o">.</span><span class="n">documentElement</span><span class="p">)</span> <span class="k">if</span> <span class="n">fc_return</span><span class="o">.</span><span class="n">Success</span><span class="p">:</span> <span class="nb">print</span><span class="p">(</span><span class="s1">'Weather forecast for </span><span class="si">%s</span><span class="s1">, </span><span class="si">%s</span><span class="s1">:'</span> <span class="o">%</span> <span class="p">(</span><span class="n">fc_return</span><span class="o">.</span><span class="n">City</span><span class="p">,</span> <span class="n">fc_return</span><span class="o">.</span><span class="n">State</span><span class="p">))</span> <span class="k">for</span> <span class="n">fc</span> <span class="ow">in</span> <span class="n">fc_return</span><span class="o">.</span><span class="n">ForecastResult</span><span class="o">.</span><span class="n">Forecast</span><span class="p">:</span> <span class="n">when</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">'%A, %B </span><span class="si">%d</span><span class="s1"> %Y'</span><span class="p">,</span> <span class="n">fc</span><span class="o">.</span><span class="n">Date</span><span class="o">.</span><span class="n">timetuple</span><span class="p">())</span> <span class="n">outlook</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="n">Desciption</span> <span class="c1"># typos in WSDL left unchanged</span> <span class="n">low</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="n">Temperatures</span><span class="o">.</span><span class="n">MorningLow</span> <span class="n">high</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="n">Temperatures</span><span class="o">.</span><span class="n">DaytimeHigh</span> <span class="nb">print</span><span class="p">(</span><span class="s1">' </span><span class="si">%s</span><span class="s1">: </span><span class="si">%s</span><span class="s1">, from </span><span class="si">%s</span><span class="s1"> to </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">when</span><span class="p">,</span> <span class="n">outlook</span><span class="p">,</span> <span class="n">low</span><span class="p">,</span> <span class="n">high</span><span class="p">))</span> </pre></div> </div> <p>And run it:</p> <div class="highlight-default"><div class="highlight"><pre><span></span>llc[567]$ python client_get.py Weather forecast for Saint Paul, MN: Wednesday, August 13 2014: Partly Cloudy, from 63 to 83 Thursday, August 14 2014: Partly Cloudy, from 61 to 82 Friday, August 15 2014: Partly Cloudy, from 65 to 86 Saturday, August 16 2014: Partly Cloudy, from 67 to 84 Sunday, August 17 2014: Partly Cloudy, from 67 to 82 Monday, August 18 2014: Partly Cloudy, from 67 to 83 Tuesday, August 19 2014: Partly Cloudy, from 65 to 84 </pre></div> </div> <p>That’s it.</p> <table class="docutils footnote" frame="void" id="id2" rules="none"> <colgroup><col class="label" /><col /></colgroup> <tbody valign="top"> <tr><td class="label"><a class="fn-backref" href="#id1">[*]</a></td><td><strong>Note</strong>: Sometime between 2014 and 2017 the CDYNE Weather Service disappeared, although as of 2017-05-13 the link to its description above was still present. If you care about weather, there is a more complex example interfacing with the <a class="reference external" href="http://www.nws.noaa.gov/ndfd/">National Digital Forecast Database</a> in the <code class="docutils literal"><span class="pre">examples/ndfd</span></code> directory.</td></tr> </tbody> </table> </div> <div class="section" id="indices-and-tables"> <h2>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h2> <ul class="simple"> <li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li> <li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li> </ul> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="#">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">PyXB: Python XML Schema Bindings</a><ul> <li><a class="reference internal" href="#getting-help">Getting Help</a></li> <li><a class="reference internal" href="#contents">Contents</a></li> <li><a class="reference internal" href="#thirty-second-example">Thirty Second Example</a></li> <li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li> </ul> </li> </ul> <h4>Next topic</h4> <p class="topless"><a href="overview.html" title="next chapter">Overview</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/index.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <form class="search" action="search.html" method="get"> <div><input type="text" name="q" /></div> <div><input type="submit" value="Go" /></div> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="overview.html" title="Overview" >next</a> |</li> <li class="nav-item nav-item-0"><a href="#">PyXB 1.2.6 documentation</a> »</li> <li style="margin-left: 20px">PyXB hosted on <a href="http://sourceforge.net/projects/pyxb"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=263147&type=9" width="80" height="15" alt="Get PyXB: Python XML Schema Bindings at SourceForge.net. Fast, secure and Free Open Source software downloads"/></a></li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2009-2017, Peter A. Bigot. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.5. </div> </body> </html>