[Fedora-suds-list] Elements with attributes and text

Jeff Ortel jortel at redhat.com
Wed May 5 18:21:32 UTC 2010


Hey Dennis,

Sorry for the slow reply.  Been busy :)

See below:

On 05/03/2010 01:32 PM, Dennis Tomas wrote:
> Hello,
>
> I have a general question about suds, which I couldn't answer by reading
> the suds documentation. Suppose there are the following types in a wsdl:
>
> <xs:complexType name="ParamType">
>    <xs:simpleContent>
>      <xs:extension base="xs:anySimpleType">
>        <xs:attribute name="n" type="xs:token" use="required"/>
>      </xs:extension>
>    </xs:simpleContent>
> </xs:complexType>
>
> <xs:complexType name="ParamListType">
>    <xs:sequence>
>      <xs:element maxOccurs="unbounded" minOccurs="0" name="P"
>                  type="xx:ParamType"/>
>    </xs:sequence>
> </xs:complexType>
>
> and there is a method doSomething(ParamListType Params), which I want to
> call so that the resulting SOAP request would look like this:
> <SOAP-ENV:Envelope
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
>     <SOAP-ENV:Header/>
>     <SOAP-ENV:Body>
>        <DoSomethingRequest xmlns="...">
>           <Params>
>              <P n="foo">bar</P>
>           </Params>
>        </DoSomethingRequest>
>     </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
>
> Now what is the correct object represention for element "P" with
> attribute n="foo" and text "bar"? I hope I'm not missing something very
> obvious here...

This is kind of obscure because it's rare.  The suds.sudsobject.Property class is for 
mixed content.  You can create as:

from suds.sudsobject import Property
p = Property('bar')
p._n = 'foo'  # <-- attribute

Or, using the factory:

p = client.factory.craete('ParamType')
p.value = 'bar'
p._n = 'foo'

The factory will see that it is a mixed element and create a property.

The marshaller knows to marshal Property objects as:

<P n="foo">bar</P>

>
> Regards,
>
> Dennis
>
> _______________________________________________
> suds mailing list
> suds at lists.fedoraproject.org
> https://admin.fedoraproject.org/mailman/listinfo/suds

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5126 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.fedoraproject.org/pipermail/suds/attachments/20100505/48c9ade8/attachment-0001.bin 


More information about the suds mailing list