[xsde-users] handling content of anyType

Boris Kolpackov boris at codesynthesis.com
Wed Jun 18 03:03:13 EDT 2008


Hi Ninh,

In the future please send technical questions like these to the
xsde-users mailing list (which I've CC'ed) instead of to me directly.
This way other developers who may have experienced a similar problem
can provide you with a solution. Plus questions and answers will be
archived and available to others with similar problems.


Ninh Tran Dang <tdninh at tma.com.vn> writes:

> I have trouble when using XSDe to parse an empty element. The root parser
> class doesn't allow me to set the parser for the person element.
> 
> Because the element type under the root node is anyType, so it will accept
> all xml elements under the root provided they are validated themselves, but
> in this case I cannot parse the xml document.

More precisely, anyType accepts any well-formed XML fragment. There
won't be any XML Schema validation though. For example, in the sample
XML you provided below, the person element won't be validated against
the person element defined in the schema.


> Could you answer me whether XSDe supports to parse this kind of schema? Or
> do we have anyway to overcome this situation?

Similar to wildcards (any and anyAttribute) all content matched by
anyType will be reported via the following "raw XML" callbacks:

  virtual void
  _start_any_element (const xml_schema::ro_string& ns,
                      const xml_schema::ro_string& name);

  virtual void
  _end_any_element (const xml_schema::ro_string& ns,
                    const xml_schema::ro_string& name);

  virtual void
  _any_attribute (const xml_schema::ro_string& ns,
                  const xml_schema::ro_string& name,
                  const xml_schema::ro_string& value);

  virtual void
  _any_characters (const xml_schema::ro_string&);
 
You can override them in root_pimpl. If you know that the content
matched by anyType can be parsed by some other parser (e.g., 
person_pimpl in the below example), then you can route these calls
to the corresponding parser. For more information on how to do
this refer to the wildcard example in examples/cxx/parser/wildcard/.

Boris


[The rest of the original email follows for context.]

> 
> Thanks,
> 
> Ninh
> 
> <root xsi:noNamespaceSchemaLocation="E:\temp\conf\question.xsd"
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> 
>  <person>
>    <first-name>String</first-name>
>    <last-name>String</last-name>
>  </person>
> 
> </root>
> 
>  
> 
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>            elementFormDefault="qualified" 
>            attributeFormDefault="unqualified">
> 
> <xs:element name="root">
>   <xs:complexType>
>     <xs:complexContent>
>       <xs:extension base="xs:anyType">
>       </xs:extension>
>     </xs:complexContent> 
>   </xs:complexType>
> </xs:element>
> 
> <xs:element name="person">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element name="first-name" type="xs:string"/>
>       <xs:element name="last-name" type="xs:string"/>
>     </xs:sequence>
>   </xs:complexType>
> </xs:element>
> 
> </xs:schema>




More information about the xsde-users mailing list