[xsd-users] retrieving data from wildcard element

Keith Milhouse kmilhous at yahoo.com
Mon Jun 11 06:41:45 EDT 2012


Thanks Boris.  I had been through those examples before but instead of just extracting the data in Value from the node n using the DOM Interface, I was attempting to cast to type Value and use it.  I'm curious why casting to Value and using its container still does not allow me to retrieve the data stored in Value.

// From using the mixed example.
// Found Element Node Value
xml_schema::type & t(*reinterpret_cast<xml_schema::type*> (n->getUserData(xml_schema::dom::tree_node_key)));
Value& a(dynamic_cast<Value&> (t));

Value::any_optional &valO = a.any();

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

valO is not present.  Any ideas what I'm doing wrong?


thanks,
Keith Milhouse




________________________________
 From: Boris Kolpackov <boris at codesynthesis.com>
To: Keith Milhouse <kmilhous at yahoo.com> 
Cc: "xsd-users at codesynthesis.com" <xsd-users at codesynthesis.com> 
Sent: Monday, June 11, 2012 5:35 AM
Subject: Re: [xsd-users] retrieving data from wildcard element
 
Hi Keith,

Keith Milhouse <kmilhous at yahoo.com> writes:

> I have a schema where I am not able to retrieve the wildcard element's
> value from the parsed xml.
>
> [...]
>
>       <xs:element name="Value" minOccurs="0">
>         <xs:complexType mixed="true">
>           <xs:sequence>
>             <xs:any processContents="lax" minOccurs="0"/>
>           </xs:sequence>
>         </xs:complexType>
>       </xs:element>
>
> Sample XML:
>
> [...]
>
>         <Value>true</Value>

This is not really wildcard content. xs:any in the above type will match
any nested element. But what you have is text, which is allowed thanks to
the type having mixed content (mixed="true"). In other words, if you had
something like this:

<Value><Text>true</Text></Value>

Then there would be an element (<Text>true</Text>) in the wildcard content.
The way it is now, you will need to retrieve it as mixed content. See the
'mixed' and 'custom/mixed' examples for details on how this can be done.

Boris


More information about the xsd-users mailing list