[BangPypers] Mapping python types to xml schema

Anand Balachandran Pillai abpillai at gmail.com
Mon May 12 15:02:23 CEST 2008


        Is your problem in actually finding out the types or in
arriving at a type
mapping ? If the question is regarding mapping I think you can simply
pass in datetime objects as seconds since epoch, in this case it will
be mapped to a FLOAT or DOUBLE.

        The other option is to convert it to a string type using the "isoformat"
method. This is the better option I think, since it can also contain the time
zone information if any, contained in the datetime object.

      But can't you use javax.xml.namespace.QName XSD_DATETIME for
representing date and time ?

       Complex types are more tricky, since you cannot resolve it to
a single type. It can be represented as a two tuple (x, y) of floats, where
x is the real part and y the imaginary part.

     Also take a look at how derived types are encoded in XML-RPC in Python.
It could be useful.



On Mon, May 12, 2008 at 4:35 PM, Heshan Suriyaarachchi
<heshan.suri at gmail.com> wrote:
> Hi,
>   I am using a mechanism to annotate a python script, and at the deployment
> time I am reading the annotations and mapping the types defined in the
> python script to xml schema types(This is done inside java).But the problem
> I am facing is , since python is dynamically typed how should I map the date
> , time types , complex types?(I have attached below some sample code to give
> you an idea). The information in [1] gives a bit of an idea but it does not
> give any detail description.I will be grateful if anyone can give me any
> direction on mapping python types to xml schema.(either in python or in
> java)
> // my java imports
> import org.apache.ws.commons.schema.constants.Constants;
> // my java code
>     HashMap simpleTypetoxsd = new HashMap();
>     simpleTypetoxsd.put("int", Constants.XSD_INT);        // i.e. I am
> mapping my "int" annotation to schema type XSD_INT
>         simpleTypetoxsd.put("integer", Constants.XSD_INT);
>         simpleTypetoxsd.put("Integer", Constants.XSD_INT);
>         simpleTypetoxsd.put("double", Constants.XSD_DOUBLE);
>         simpleTypetoxsd.put("Double", Constants.XSD_DOUBLE);
>         simpleTypetoxsd.put("string", Constants.XSD_STRING);
>         simpleTypetoxsd.put("String", Constants.XSD_STRING);
> [1] -
> http://jython.org/Project/userguide.html#calling-java-methods-and-functions
> Thanx in advance
> --
> Regards,
> Heshan Suriyaarachchi
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers


More information about the BangPypers mailing list