[Xml-compile] Two concrete types in one schema

Roman Daniel roman.daniel at davosro.cz
Thu Jan 28 11:20:17 GMT 2010


Hi Mark,

yes, I know that the xsi:type is deprecated, but we have them in our schema
and with XSI_TYPE it was a snap, until I crush into a problem described
below.

We have
- an abstract type A in schema1
- two concrete types T1 and T2 in schema2
- element E using the abstract type in schema3

When I write XML where E is using T1, everything is OK
When I write XML where E is using T2, it seems like writer is still parsing
T1 and reports error.

The behaviour seems to be dependent on order of concrete types in xsi_type
argument of compile,
having xsi_type =3D> { A =3D> [T1, T2] } results in problem with T2, while
xsi_type =3D> { A =3D> [T2, T1] }
results in problem with T1.
Using concrete types from more schemas (one type per schema) didn't cause
problems.

Is it a bug or is there something I missing?

Thank you for reply,

Roman Daniel
----------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use XML::Compile::Schema;
use XML::Compile::Util qw(pack_type);

my $ABSTRACT_NS =3D 'http://abstract.to';
my $USAGE_NS    =3D 'http://usage.to';
my $CONCRETE_NS =3D 'http://concrete.to';


my $schema =3D XML::Compile::Schema->new;

# abstract
$schema->importDefinitions( <<"END_ABSTRACT");
<xs:schema
    xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
    targetNamespace=3D"$ABSTRACT_NS"
    elementFormDefault=3D"qualified">
<xs:complexType name=3D"typeAbstract" abstract=3D"true" />
</xs:schema>
END_ABSTRACT

# element using the type
$schema->importDefinitions(<<"END_USAGE");
<xs:schema
    xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
    xmlns:Abstract=3D"$ABSTRACT_NS"
    targetNamespace=3D"$USAGE_NS"
    elementFormDefault=3D"qualified">

<xs:import namespace=3D"$ABSTRACT_NS" />

<xs:element name=3D"usage">
    <xs:complexType>
      <xs:sequence>
        <xs:element name=3D"payload" type=3D"Abstract:typeAbstract"/>
      </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>
END_USAGE
# concrete types
$schema->importDefinitions(<<"END_CONCRETE");
<xs:schema
    xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
    xmlns:Abstract=3D"$ABSTRACT_NS"
    targetNamespace=3D"$CONCRETE_NS"
    elementFormDefault=3D"qualified">

<xs:import namespace=3D"$ABSTRACT_NS" />

<xs:complexType name=3D"typeConcrete1">
    <xs:complexContent>
        <xs:extension base=3D"Abstract:typeAbstract">
            <xs:sequence>
                <xs:element name=3D"id" type=3D"xs:string" />
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name=3D"typeConcrete2">
    <xs:complexContent>
        <xs:extension base=3D"Abstract:typeAbstract">
            <xs:sequence>
                <xs:element name=3D"word" type=3D"xs:string" />
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>


</xs:schema>

END_CONCRETE

my $writer =3D $schema->compile(
    WRITER   =3D> pack_type( $USAGE_NS, 'usage' ),
    xsi_type =3D> {
        pack_type( $ABSTRACT_NS, 'typeAbstract' ) =3D> [
            pack_type( $CONCRETE_NS, 'typeConcrete1' ),
            pack_type( $CONCRETE_NS, 'typeConcrete2' ),
        ]
    }
);

{
    my $doc =3D XML::LibXML::Document->new;
    my $elem =3D $writer->(
        $doc,
        {   payload =3D> {
                XSI_TYPE =3D> pack_type( $CONCRETE_NS, 'typeConcrete1' ),
                id       =3D> 'SOME ID',
            }
        }
    );
    warn $elem->toString(1);
}
{
    my $doc =3D XML::LibXML::Document->new;
    my $elem =3D $writer->(
        $doc,
        {   payload =3D> {
                XSI_TYPE =3D> pack_type( $CONCRETE_NS, 'typeConcrete2' ),
                word       =3D> 'SOMEWORD',
            }
        }
    );
    warn $elem->toString(1);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20100128/01=
4ab588/attachment.htm


More information about the Xml-compile mailing list