Menu

Attribute with the structure prefix:attribute_local_name

Get Help
Anonymous
2014-01-21
2014-01-21
  • Anonymous

    Anonymous - 2014-01-21

    Hi,
    I am currently using the libraries without schema. What I would like to have is a XML that has the attribute as QName.

    <tns:application xmlns:tns="blabla" tns:id="app"/>

    In the examples I only found how to do:

    <tns:application xmlns:tns="blabla" id="app"/>

    What I am doing now is:

    ...
    TRY_CATCH_ENCODE(serialize.startDocument(&testStrm));

    qname.uri = &NS_ETSI_M2M;
    qname.localName = &APPLICATION;
    
    TRY_CATCH_ENCODE(serialize.startElement(&testStrm, qname, &valueType)); // <application>
    
        if (appId.length!=0)
        {
                //qname.uri = &NS_ETSI_M2M;
                qname.localName = &APP_ID;
    
                TRY_CATCH_ENCODE(serialize.attribute(&testStrm, qname, TRUE, &valueType)); // attribute appId"
        TRY_CATCH_ENCODE(asciiToString(appId.str, &chVal, &testStrm.memList, FALSE));
        TRY_CATCH_ENCODE(serialize.stringData(&testStrm, chVal));
        }
    
    TRY_CATCH_ENCODE(serialize.endElement(&testStrm)); //<spplication>
    
    TRY_CATCH_ENCODE(serialize.endDocument(&testStrm));
    

    ...

    How do I obtain an attribute with the structure prefix:attribute_local_name ?

    Thank you!

    Francesca

     
  • Rumen Kyusakov

    Rumen Kyusakov - 2014-01-21

    Hi Francesca,

    The second parameter of the function serialize.attribute() is "qname" - this is the qualified name of the attribute. In your example you set only the local name and the namespace (uri) is still NS_ETSI_M2M (maybe that is intended??):

    //qname.uri = &NS_ETSI_M2M;
    qname.localName = &APP_ID;
    

    Back to your last question - prefix:attribute_local_name. In XML/EXI the prefix is just a short notation for the namespace (uri). In EXI you encode the qualified name for elements/attributes each time you encode them. So it does not use prefixes by default. Note that in most cases, prefixes are not really needed - they rarely carry any information but rather are only use to shorten the namespace references.
    If you really need the prefixes (most likely not) you need to use the preserve prefixes fidelity option in the EXI header:

    SET_PRESERVED(strm.header.opts.preserve, PRESERVE PREFIXES);
    

    Best regards,
    Rumen

     

Anonymous
Anonymous

Add attachments
Cancel