[xsd-users] Serializing just the contents of an "any" element

Iain Sharp isharp at atis.org
Mon Jun 19 12:40:07 EDT 2017


Hi Folks,

I am working on a feasibility-study to use the C++ XSD tree tool to work on the XSDs defined for the oneM2M IoT standard (http://www.onem2m.org/).

What I need to do is to just serialize the contents of an "any" - without its parent - in to the body of an HTTP request. I am really struggling to work out how to do this.

Specifically the relevant XSD fragment is:
              <xs:complexType name="primitiveContent">
                             <xs:choice minOccurs="0" maxOccurs="unbounded">
                                           <xs:any namespace="http://www.onem2m.org/xml/protocols" processContents="lax" />
                                           <xs:any namespace="##other" processContents="lax"  />
                             </xs:choice>
              </xs:complexType>

I can write any object from the schema in to the 1st "any" of this element OK. I can serialize a "primitiveContent" or any parent of that element OK, but I can't seem to work out how to serialize just the contents of the "any" without also getting some of it's parent. If you could suggest the right direction that would be very helpful.

What I get at the moment is:
<m2m: primitiveContent xmlns:m2m="http://www.onem2m.org/xml/protocols">
  <m2m:ae rn="myAE" xmlns:m2m="http://www.onem2m.org/xml/protocols">
    <api>myAE</api>
    <aei>myAE</aei>
    <rr>true</rr>
  </m2m:ae>
</m2m: primitiveContent >

What I want is:
  <m2m:ae rn="myAE" xmlns:m2m="http://www.onem2m.org/xml/protocols">
    <api>myAE</api>
    <aei>myAE</aei>
    <rr>true</rr>
  </m2m:ae>

I suppose I could just strip the 1st and last lines off the serialization of the parent, but that doesn't seem like a quality solution!

Regards

Iain



More information about the xsd-users mailing list