Hey,

I'm trying to get the response from spyne to match up with a set of
fixed schemas, and I'm running to a wall trying to deal with
referenced elements. As an example, using these two schema files:

base.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://xml.test.org/base";
    xmlns:a="http://xml.test.org/addon";
    xmlns:b="http://xml.test.org/base";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified">
    <xs:import namespace="http://xml.test.org/addon";
schemaLocation="addon.xsd"/>
    <xs:element name="Test" type="b:TestBase" />
    <xs:complexType name="TestBase">
        <xs:sequence>
            <xs:element name="Value" type="xs:string" />
            <xs:element ref="a:Addon" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

addon.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://xml.test.org/addon";
    xmlns:a="http://xml.test.org/addon";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified">
    <xs:element name="Addon" type="a:AddonType" />
    <xs:simpleType name="AddonType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="1" />
            <xs:enumeration value="2" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

the result should be something like:

<?xml version="1.0" encoding="UTF-8"?>
<b:Test xmlns:a="http://xml.test.org/addon";
 xmlns:b="http://xml.test.org/base";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
    <b:Value>Value0</b:Value>
    <a:Addon>1</a:Addon>
</b:Test>

but whatever I try, I can't figure out how to change the namespace of
immediate children with the spyne classes (while in this case I'm
dealing with enumerations, I can't seem to change it for any other
types either, complex or not).

As a quick example of one way I'm trying to solve this:
addon = Enum('1', '2', type_name='Addon')
addon.__namespace__ = 'http://xml.test.org/addon'

class Test(ComplexModel):
    __namespace__ = 'http://xml.test.org/base'
    Value = String
    Addon = addon

test = Test(Value='1', Addon='2')
print lxml.etree.tostring(get_object_as_xml(test), pretty_print=True)

results in:
<ns0:Test xmlns:ns0="http://xml.test.org/base";>
  <ns0:Value>1</ns0:Value>
  <ns0:Addon>2</ns0:Addon>
</ns0:Test>

That all said, if there is a way to just return raw xml to the client,
that'd work as a workaround for me just fine.

- Joni
_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap

Reply via email to