Dear Joseph,

On Wed, 2014-07-16 at 10:15 -0700, jgagnon wrote:
> I have written an application that generates XML files that represent test
> cases for a collection of types defined by an XML schema.  Some of these
> types contain elements that are abstract.  The logic locates all concrete
> implementers of the abstract type and when an instance is generated,
> processes one of the concrete types in place of the abstract type.
> 
> It's my understanding that the element must have a type reference attribute
> that indicates the concrete type name.  So, as an example:
> 
> ...
>   <SomeElement xsi:type="ConcreteType">
>     ... content ...
>   </SomeElement>
> ...
> 
> The schema defines the SomeElement field as being defined by an abstract
> type.  ConcreteType is one of many possible concrete implementers of that
> abstract type.
> 
> To take this a little further, a namespace entry is made in the document
> that defines a prefix for the schema types.  So, in the root element there
> would be entry like:
> 
> <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns:myPrefix="http://my-schema-site"/>
> 
> The prefix is applied to all elements that are defined by the schema.  E.g.
> <myPrefix:SomeElement>.  I would also assume that the prefix needs to be
> used in the concrete type reference. So, what I have above now becomes:
> 
> ...
>   <SomeElement xsi:type="myPrefix:ConcreteType">
>     ... content ...
>   </SomeElement>
> ...
> 
> My application does all of this.
> 
> I have also added the option to validate the instance once it's been
> generated.  *Here is where the problem enters the story.*  For some reason,
> it fails validation with the complaint:
> 
> error: cvc-elt.4.2: Invalid xsi:type qname: 'myPrefix:ConcreteType' in
> element SomeElement@my-schema-site

IIRC XMLBeans implements XMLSchema 1.0 rather than 1.1, so this error
refers to clause 4.2 of this validation rule:

<http://www.w3.org/TR/xmlschema-1/#cvc-elt>

It looks as if the XML schema definition of myPrefix:ConcreteType is not
found or not accessible. Earlier you wrote:

> The logic locates all concrete implementers of the abstract type

This may be the problem: if by "concrete implementers" you mean types
defined in Java that simply implement/extend XMLBeans-generated types,
your implementing types have no presence within the schema type system
that XMLBeans generates. You have not stated explicitly whether or not
your concrete types are defined in XML schemata or not. If not, there is
no way that XMLBeans can know about them. If this is what you are doing,
you need to generate additional XML schemata that define your concrete
types (overriding the abstract types that are defined in your existing
XML schema by either restriction or extension). Compile these schemata
and the XMLBeans-generated API should allow you to work with the
concrete types, including instantiating them automatically and correctly
from parsed XML. On output, the xsi:type elements will also be written
automatically by the XMLBeans-generated API without you having to worry
about them.

Alternatively, you could generate your own implementations of
<http://xmlbeans.apache.org/docs/2.6.0/reference/org/apache/xmlbeans/SchemaType.html>
 and 
<http://xmlbeans.apache.org/docs/2.6.0/reference/org/apache/xmlbeans/SchemaTypeSystem.html>.
 This seems to me to be a much harder approach, although it may be worthwhile 
if you absolutely have to map existing Java types to XML Schema types.

> Oddly, if I validate the instance externally using XMLBeans validate utility
> (.../xmlbeans-2.6.0/bin/validate), there is no complaint.

Did you do 'validate -strict'?

> Am I doing something wrong?

Without knowing more about what you are doing, it is hard to say. FWIW,
I do something very like this (defining all my concrete types in XML
schemata) and I don't have any validation problems.

Hope that this helps,
Peter.

-- 
Peter Keller                                     Tel.: +44 (0)1223 353033
Global Phasing Ltd.,                             Fax.: +44 (0)1223 366889
Sheraton House,
Castle Park,
Cambridge CB3 0AX
United Kingdom



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: user-h...@xmlbeans.apache.org

Reply via email to