Search code examples
pythondjangorpcxml-rpcspyne

Spyne. How can i make service for one tag xml


Worked on python 2.7, django 1.6, spyne 2.11

I have this xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE inquiry_A2 SYSTEM "inquiry_A2.dtd">
<!-- Optional -->
<inquiry_A2>
    <!-- Optional -->
    <Consignee>
        <AgencyCode>123123</AgencyCode>
        <PartyID>123123</PartyID>
    </Consignee>
    <SubstitutionIndicator>123123</SubstitutionIndicator>
    <Campaign>123123</Campaign>
    <DocumentID>1</DocumentID>
</inquiry_A2>

inquiry_A2 is a root element I want to make spyne proceed this request, but i can't figure out how to make this? The problem is that spyne rpc need both method name and param, for example:

@rpc(RequestInquiry)
def inquiry_A2(ctx, inquiry_A2):
    return True

But with this example spyne generated xml is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE inquiry_A2 SYSTEM "inquiry_A2.dtd">
<!-- Optional -->
<inquiry_A2>
    <inquiry_A2>
        <!-- Optional -->
        <Consignee>
            <AgencyCode>123123</AgencyCode>
            <PartyID>123123</PartyID>
        </Consignee>
        <SubstitutionIndicator>123123</SubstitutionIndicator>
        <Campaign>123123</Campaign>
        <DocumentID>1</DocumentID>
    </inquiry_A2>
</inquiry_A2> 

Is that possibile to do with spyne? I can't change incoming xml


Solution

  • You need:

    @rpc(RequestInquiry, _body_style='bare')
    def inquiry_A2(ctx, inquiry_A2):
        return True