Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc

Reply
Thread Tools

Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc

 
 
Acácio Centeno
Guest
Posts: n/a
 
      02-14-2013
Hi, I've searched both this group and the web but was unable to find an answer, sorry if it has already been answered, it seems such a common problem that I’m sure someone has asked before.

We have a WebServices platform that must reply in XML, JSON, or JSONP. Having to convert between these formats is a really pain in the neck.

What I’d like to do is, given some schema representation, that could be aDTD, XSD or whatever and a python dictionary with the values for each node, generate the output in either XML, JSON or JSONP.

For instance, if the XSD would be:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlnss="http://www.w3.org/2001/XMLSchema">
<xs:element name="Foo"></xs:element>
<xs:element name="Baz"></xs:element>
<xs:element name="Choice" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A" />
<xs:enumeration value="B" />
<xs:enumeration value="C" />
<xs:enumeration value="D" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>

And given the following dict:

{
“foo”: “bar”,
“hello”: “world”,
“choice”: “B”,
“callback”: “process_server_reply”
}

Be able to generate either this XML:

<xml>
<Foo>Bar</Foo>
<Hello>World</Hello>
<Choice>B</Choice>
</xml>

Or this JSON:

{
"foo": "bar",
"hello": "world",
"choice": "B"
}

Or this JSONP:

process_server_reply({"foo": "bar","hello": "world","choice": "B"});


Which library/technique would you guys recommend for this kind of scenario?

Thanks in advance.
 
Reply With Quote
 
 
 
 
dieter
Guest
Posts: n/a
 
      02-15-2013
Acácio Centeno <(E-Mail Removed)> writes:

> Hi, I've searched both this group and the web but was unable to find an answer, sorry if it has already been answered, it seems such a common problem that I am sure someone has asked before.
>
> We have a WebServices platform that must reply in XML, JSON, or JSONP. Having to convert between these formats is a really pain in the neck.
>
> What I would like to do is, given some schema representation, that could be a DTD, XSD or whatever and a python dictionary with the values for each node, generate the output in either XML, JSON or JSONP.


You could have a look at the PyPI packages "dm.zope.rpc"
and "dm.zope.rpc.wsdl_suds". They provide a middleware
to support protocol independent web services (for the
"Zope" application server). Together, they support
XML-RPC, JSON-RPC and WSDL decribed SOAP web services.
As you are likely not using Zope, you probably cannot use
these packages directly but you may get some ideas how
to create such a middleware for your web framework.

Python (from 2.6 on) has "json" support. Thus converting
a dict to "json" is simple ("json.dumps").

"dm.zope.rpc.wsdl_suds" abuses "suds" to parse the WSDL
and generate appropriate SOAP responses from a dict.
Alternatively, you might use "PyXB" for that.

You could also have a look at "Spyne" (formerly known (among others)
as "rpclib"). I think (but am not sure) that it targets
your use case for the "twisted" environment.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lib depending on Lib, packaging for distro Christopher C++ 4 11-01-2007 10:36 PM
difference between libboost_regex-mt-gd-1_33_1.lib and boost_regex-mt-gd-1_33_1.lib ideal.black@gmail.com C++ 3 09-30-2007 06:54 AM
how to debug this error? /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o Durduran C Programming 10 07-30-2007 09:03 PM
Need odbc32.lib odbccp32.lib Praetorian C++ 1 04-20-2006 07:14 PM
Diff betw common/lib and shared/lib in Tomcat James Yong Java 0 09-12-2005 02:36 AM



Advertisments