[xsd-users] retrieving data from wildcard element

Keith Milhouse kmilhous at yahoo.com
Sun Jun 10 12:27:36 EDT 2012


I have a schema where I am not able to retrieve the wildcard element's value from the parsed xml.  The element in question is 'Value' in the below schema.  When examining the "Value:any_optional", the .present() check always fails.  Disabling the check and attempting to create a DOMElement using the any_optional get method generates a seg fault with this msg - "RuntimeError: Error reading string from inferior: Input/output error".  Retrieving dom_document() from the Value object provides the same kind of seg fault when examining its contents.  The schema is a scaled down version of one that I'm required to use, so I can't change its design.   

I'm running on CentOS 5.8, using xsd-3.3.0.1 and xerces 2.7.  


I'm generating source from schema with the following command.

xsdcxx cxx-tree  --generate-ostream --generate-wildcard --generate-inline  CommandMessage.xsd

Code Snippet:
std::auto_ptr<CommandMessage> cmd(
                CommandMessage_(
                        dom1,
                        xml_schema::flags::keep_dom
                                | xml_schema::flags::dont_initialize, props)); // works with props

        CommandMessage::Command_optional cmds = cmd->Command();

        if (cmds != NULL)
        {
            CommandType ct = cmds.get();

            CommandType::ExtendedCommand_type extCmd = ct.ExtendedCommand();
      
            ExtendedCommandType::Parameter_sequence &ps = extCmd.Parameter();
            for (ExtendedCommandType::Parameter_const_iterator b(ps.begin()),
                    e(ps.end()); b != e; ++b)
            {

                cout << "Parameter DataType:" << b->DataType() << endl;
                AnnotatedDataType::Value_optional val = b->Value();
                cout << "Parameter Value   :" << b->Value().get() << endl;

                Value value = b->Value().get();

                Value::any_optional &valO = value.any();
                if (valO.present())
                {
                    DOMElement &elem(valO.get());
                    cout << "Elem local name = " << xsd::cxx::xml::transcode<
                            char>(elem.getLocalName()) << endl;
                }
}


Schema:
<?xml version="1.0" encoding="Uthanks for the help.  TF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="CommandMessage">
 <xs:complexType>
    <xs:sequence>
      <xs:element name="Command" type="CommandType" minOccurs="0">
          <xs:annotation>
            <xs:documentation>The issued command.</xs:documentation>
          </xs:annotation>
       </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element> 


 <xs:complexType name="CommandType">
    <xs:annotation>
      <xs:documentation>The type of command.</xs:documentation>
    </xs:annotation>
    <xs:choice> 
      <xs:element name="ExtendedCommand" type="ExtendedCommandType"/>
    </xs:choice>
  </xs:complexType>

  <xs:complexType name="ExtendedCommandType">
    <xs:annotation>
      <xs:documentation>Extended command, allowing extensible command structures. </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="Parameter" type="AnnotatedDataType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="Command" type="xs:string" use="required"/>
    <xs:attribute name="Enabled" type="xs:boolean" default="true"/>
  </xs:complexType>

  <xs:complexType name="AnnotatedDataType">
    <xs:sequence>
      <xs:element name="Value" minOccurs="0">
        <xs:annotation>
          <xs:documentation>
            Based upon the value of the DataType attribute, value can contain contain an instance of a standard XSD data type.
          </xs:documentation>
        </xs:annotation>
        <xs:complexType mixed="true">
          <xs:sequence>
            <xs:any processContents="lax" minOccurs="0"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
     <xs:attribute name="DataType" type="xs:string" use="required"/>
  </xs:complexType>

</xs:schema>

Sample XML:
<CommandMessage MessageType="Request" RequestId="R_ID"  TimeStamp="2012-05-23T17:43:15.373Z">
  <Command>
    <ExtendedCommand Command="Silence">
      <Parameter Name="Enable" DataType="xs:boolean">
        <Value>true</Value>
      </Parameter>
    </ExtendedCommand>
  </Command>
</CommandMessage>

Not sure what I'm missing.
thanks,
Keith Milhouse


More information about the xsd-users mailing list