Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

How to create qualified Attribute name

Help
igorkorn
2013-04-13
2013-04-14
  • igorkorn
    igorkorn
    2013-04-13

    I try to make XMLDSIG:

    ...
    import pyxb.bundles.wssplat.wsse as wsse
    import pyxb.bundles.wssplat.wsu as wsu
    ...
    pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace( wsse.Namespace, 'wsse' )
    pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace( wsu.Namespace, 'wsu' )
    ...
    binarysecuritytoken = wsse.BinarySecurityToken('...', 
        Id='...',
        EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-messagesecurity-1.0#Base64Binary",
        ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3",
    )
    ...
    

    But attribute 'Id' must be in 'wsu' name space, that is "wsu:Id". Is there any way to do this?

     
  • Peter A. Bigot
    Peter A. Bigot
    2013-04-13

    Attribute Id is in the wsu namespace. However, the schema for both wsse and wsu have attributeFormDefault="unqualified", so the schema does not require that the namespace qualifier be present in the xml text.

    PyXB does not have a flag that forces the namespace qualifier to be emitted even when it is not necessary.

    PyXB may not handle attributeFormDefault="qualified" correctly; I need to investigate that to be sure, but it's not relevant to these schema.

    If in the above you use:

    import pyxb.bundles.wssplat.wsse as wsse
    import pyxb.bundles.wssplat.wsu as wsu
    import pyxb.utils.domutils
    
    pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace( wsse.Namespace, 'wsse' )
    pyxb.utils.domutils.BindingDOMSupport.DeclareNamespace( wsu.Namespace, 'wsu' )
    
    binarysecuritytoken = wsse.BinarySecurityToken('content',
                                               Id='id',
                                               EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-messagesecurity-1.0#Base64Binary",
                                               ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3")
    
    print binarysecuritytoken.toxml('utf-8')
    

    the instance is created properly, at least with the versions I'm using. ('...' is not valid for xsd:ID which is the type of the Id attribute, so the exact example you gave does not work.)

    Does that help? If not, please provide a more complete example including what you see and why you think it's wrong.

     
  • Peter A. Bigot
    Peter A. Bigot
    2013-04-13

    OK, that last answer was bogus. There are several problems, but I believe only one affects your code. The issue is that the bindings for wsse attempt to look up the module associated with the wsu bindings in order to associate that namespace with the Id attribute. The wsse bindings should have imported the wsu module so this lookup would succeed, but they didn't.

    This is now https://sourceforge.net/apps/trac/pyxb/ticket/198. You can work around it by changing the order of imports:

    import pyxb.bundles.wssplat.wsu as wsu
    import pyxb.bundles.wssplat.wsse as wsse
    
     
  • igorkorn
    igorkorn
    2013-04-14

    Thank you very much!