[xsd-users] Extracting data between xml tags

Boris Kolpackov boris at codesynthesis.com
Fri Jan 25 08:48:41 EST 2013


Hi Arul,

Prakash, Arul <Arul.Prakash2 at rsa.com> writes:

>   <xs:complexType name="ContextType" mixed="true">
>     <xs:attribute name="ID" type="xs:ID" use="optional"/>
>   </xs:complexType>
>
> [...]
> 
> My question is how can I construct  a xml fragment like this 
> < Sample ID="97612934">this is a string</ Sample >

Your type has mixed content which requires using DOM to access/modify
the data. Note also that in this particular case there is no good
reason for using mixed content. If you can change your schema, then
a much cleaner variant that achieves the same semantics would be:

  <xs:complexType name="ContextType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="ID" type="xs:ID" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

It will also be much easier to use in C++:

ContextType x ("this is a string");
x.ID ("97612934");

If you cannot change your schema and have to use the type with mixed
content, then you will need to use type customization and DOM to
access the text data. See the examples/cxx/tree/custom/mixed
example for more information on how to do this.

Boris



More information about the xsd-users mailing list