You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-user@xml.apache.org by Javier Ramos <ra...@parsec.es> on 2003/11/18 11:45:06 UTC

Problem with variable content containers ( lengthy )

Hello,

    I am trying to figure out how to deal with schemas which have 'container' elements. These elements can carry inside any number of a given set of elements. There is a very good document on how to deal with this in Schema in http://www.xfront.com/VariableContentContainers.pdf. I am using method 1 described in this document. For example, I create a document with a variable content container, which is the RequestData element:

///////////////////////////////////////////////////////////////////////////////////////////////////
///// Schema with variable content container /////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:r="http://waf.parsec.es/xmlbind/request"
    targetNamespace="http://waf.parsec.es/xmlbind/request"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

<xs:complexType name="RequestDataType">
    <xs:attribute name="creationDate" type="xs:date"/>
</xs:complexType>

<xs:element name="RequestData" abstract="true" type="rd:RequestDataType"/>

<xs:complexType name="Data">
<xs:sequence>
    <xs:element ref="rd:RequestData" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType> 

<xs:complexType name="Request">
<xs:sequence>
    <xs:element name="Data" type="r:Data" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType> 

<xs:element name="Request" type="r:Request"/>

</xs:schema>

//////////////////////////////////////////////////////////////////////////////////////////////////

Now I define a new type of RequestData, LoginRequest:

//////////////////////////////////////////////////////////////////////////////////////////////////
////// The import references the previous document //////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:rq="http://waf.parsec.es/xmlbind/request"
xmlns:r="http://parsys.parsec.es/xmlbind/request/login"
targetNamespace="http://parsys.parsec.es/xmlbind/request/login"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:import
schemaLocation="../waftypes/Request.xsd"
namespace="http://waf.parsec.es/xmlbind/request/data"
/>

<xs:complexType name="LoginRequestType">
<xs:complexContent>
    <xs:extension base="rd:RequestDataType">
        <xs:sequence>
            <xs:element name="UserId" type="xs:string"/>
        <xs:element name="Password" type="xs:string"/>
    </xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="LoginRequest" type="r:LoginRequestType" substitutionGroup="rd:RequestData"/>

</xs:schema>

////////////////////////////////////////////////////////////////////////////////////////////////////


I use XMLBeans to parse and manipulate an instance document which looks like:

/////////////////////////////////////////////////////////////////////////////////////////////////////
//////// Instance document //////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

<?xml version="1.0" encoding="UTF-8"?>
<r:Request
xmlns:xs=http://www.w3.org/2001/XMLSchema
xmlns:r="http://waf.parsec.es/xmlbind/request"
xmlns:lr="http://parsys.parsec.es/xmlbind/request/login"
>
<r:Data>
    <lr:LoginRequest>
        <UserId>ramos</UserId>
        <Password>pass</Password> 
    </lr:LoginRequest>
</r:Data>
</r:Request>

/////////////////////////////////////////////////////////////////////////////////////////////////////////

After generating code for all these schemas, I obtain a Data.java class which contains an array of RequestDataType.java classes, as expected.

I also obtain a LoginRequestType.java which extends RequestDataType, which looks very good.

The problem is that when I parse the instance document shown above, if I ask the size of the array of RequestDataType types inside the Data element I obtain zero:

    rqDoc.getRequest().getData().sizeOfRequestDataArray() is 0, where rqDoc is the RequestDocument object generated by XMLBean

This is strange. I cannot access the contents of the variable content container element.

If I use a cursor to navigate the xml code as follows:

    XmlCursor rqDataCursor = rqDoc.getRequest().getData().newCursor();
    rqDataCursor.toFirstChild();
    XmlObject singleRequest = rqDataCursor.getObject();

when debugging I obtain in singleRequest an object of type XmlAnyTypeImpl, where I expect a LoginRequestTypeImpl. In other simpler contexts, when using the getObject() method in XmlCursor I obtain the correct type.

Has anyone ever tried to do something similar? Is there a better way to do this? Why does my code not work as I expect? Must be a bug in my code or am I asking for too much expecting this to work ?

Any help will be much appreciated. 



Re: Problem with variable content containers ( lengthy )

Posted by David Bau <da...@bea.com>.
\>     Everything is setup now using XMLBeans as the java xml binding
> technology. In your opinion, if I am to deploy for production a new
> application based in this setup in approximately 6 months, should I focus
on
> XMLBeans version 1 or 2?

Right now, you should be using XMLBeans v1.

>     Right now I am dealing with version 1... Somewhere I read that version
> two will be very different. What kind of benefits can it provide?

V2 is still a work in progress at the very early stages; some features that
are being considered are listed here
http://nagoya.apache.org/wiki/apachewiki.cgi?XmlBeansFeaturePlan

A goal of v2 is to maintain good compatibility with v1, but is currently in
very early development.  I'd recommend that the best way to get the benefits
of v2 is to use v1 today, and migrate when v2 is ready.

> referenced in my previous post. Do you think it is possible to implement
> that with XMLBeans?
>
>     In that case, all the elements in the variable content container have
> the same element name, but different xsi:type. I suppose I can somehow get

Yes, this is "type substitution" and should work very well in XMLBeans!  You
should be able to use the Java "instanceof" operator to detect the different
types in the same element name.

Cheers,

David


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: Problem with variable content containers ( lengthy )

Posted by David Bau <da...@bea.com>.
\>     Everything is setup now using XMLBeans as the java xml binding
> technology. In your opinion, if I am to deploy for production a new
> application based in this setup in approximately 6 months, should I focus
on
> XMLBeans version 1 or 2?

Right now, you should be using XMLBeans v1.

>     Right now I am dealing with version 1... Somewhere I read that version
> two will be very different. What kind of benefits can it provide?

V2 is still a work in progress at the very early stages; some features that
are being considered are listed here
http://nagoya.apache.org/wiki/apachewiki.cgi?XmlBeansFeaturePlan

A goal of v2 is to maintain good compatibility with v1, but is currently in
very early development.  I'd recommend that the best way to get the benefits
of v2 is to use v1 today, and migrate when v2 is ready.

> referenced in my previous post. Do you think it is possible to implement
> that with XMLBeans?
>
>     In that case, all the elements in the variable content container have
> the same element name, but different xsi:type. I suppose I can somehow get

Yes, this is "type substitution" and should work very well in XMLBeans!  You
should be able to use the Java "instanceof" operator to detect the different
types in the same element name.

Cheers,

David


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: Problem with variable content containers ( lengthy )

Posted by Javier Ramos <ra...@parsec.es>.
Hi, David,

    Thanks for taking the time to test, I also recently made it work and was
about to send a notification to this mailing list. Of course you can add the
code to the xmlbeans test suite.

    I am a newbie to XMLBeans and having a very good experience with
xmlbeans, even admitting that I did not take enough time to read all the
documentation yet. Initially I tried to use JAXB implementations, but I find
the xmlbeans approach much more flexible and superior.

    I am starting the development of a web application framework
implementing the MVC pattern, doing the V with Cocoon, and the C with a
servlet implementing the Front Contoller pattern and containing a dispatcher
for a sereies of controllers for the different actions of the application.
The communication between Cocoon presentation layer and the front controler
is via XML, and I use an  xmlbinding technology to be able to serialize and
deserialize between Java and XML. This way I get request / response Java
objects from Schema definitions without having to write a line of code.

    Everything is setup now using XMLBeans as the java xml binding
technology. In your opinion, if I am to deploy for production a new
application based in this setup in approximately 6 months, should I focus on
XMLBeans version 1 or 2?

    Right now I am dealing with version 1... Somewhere I read that version
two will be very different. What kind of benefits can it provide?

    Also: Some time I will want to try the approach number 3 to creating
variable content containers in schema definitions described in the document
referenced in my previous post. Do you think it is possible to implement
that with XMLBeans?

    In that case, all the elements in the variable content container have
the same element name, but different xsi:type. I suppose I can somehow get
this information to be able to process element according to its type... I
will have to play more with the API. Any clue? If I get this thing working
also, are you interested in receiving a test case?

    Best regards,

        Javier Ramos


----- Original Message ----- 
From: "David Bau" <da...@bea.com>
To: <xm...@xml.apache.org>
Sent: Wednesday, November 19, 2003 1:20 PM
Subject: Re: Problem with variable content containers ( lengthy )


> Hello Javier,
>
>
> Your code works!  It did include a few typos.
>
> XMLBeans should work fine here - it is a basic case of element and type
> substitution.  (If it didn't it would be a bug in XMLBeans...) Can I add
> your test case to the xmlbeans regression test suite?
>
> Now, details.  I did need to change a few things in your schemas and XML
doc
> because the schemas didn't actually compile as you pasted them - there
were
> a couple issues where the schemas used an undefined namespace prefix, and
> another issue where you referenced an undefined element because of a
> namespace prefix mixup. Here is the actual schema that I compiled and ran:
>
>
> File 1:
>
> ====
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     xmlns:r="http://waf.parsec.es/xmlbind/request"
>     targetNamespace="http://waf.parsec.es/xmlbind/request"
>     elementFormDefault="qualified"
>     attributeFormDefault="unqualified">
>
> <xs:complexType name="RequestDataType">
>     <xs:attribute name="creationDate" type="xs:date"/>
> </xs:complexType>
>
> <xs:element name="RequestData" abstract="true" type="r:RequestDataType"/>
>
> <xs:complexType name="Data">
> <xs:sequence>
>     <xs:element ref="r:RequestData" maxOccurs="unbounded"/>
> </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="Request">
> <xs:sequence>
>     <xs:element name="Data" type="r:Data" minOccurs="1" maxOccurs="1"/>
> </xs:sequence>
> </xs:complexType>
>
> <xs:element name="Request" type="r:Request"/>
>
> </xs:schema>
> ====
>
>
> File 2:
> ====
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:rq="http://waf.parsec.es/xmlbind/request"
> xmlns:r="http://parsys.parsec.es/xmlbind/request/login"
> targetNamespace="http://parsys.parsec.es/xmlbind/request/login"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified">
>
> <xs:import
> namespace="http://waf.parsec.es/xmlbind/request/data"
> />
>
> <xs:complexType name="LoginRequestType">
> <xs:complexContent>
>     <xs:extension base="rq:RequestDataType">
>         <xs:sequence>
>             <xs:element name="UserId" type="xs:string"/>
>         <xs:element name="Password" type="xs:string"/>
>     </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> <xs:element name="LoginRequest" type="r:LoginRequestType"
> substitutionGroup="rq:RequestData"/>
>
> </xs:schema>
> ====
>
>
>
> The test case follows, which also fixes a namespace issue:
>
>
> ====
>     // Thanks to Javier Ramos
>     public void test5() throws Exception
>     {
>         String instanceSource =
>                 "<r:Request xmlns:r='http://waf.parsec.es/xmlbind/request'
> xmlns:lr='http://parsys.parsec.es/xmlbind/request/login'>" +
>                 "   <r:Data>" +
>                 "       <lr:LoginRequest>" +
>                 "           <lr:UserId>ramos</lr:UserId>" +
>                 "           <lr:Password>pass</lr:Password>" +
>                 "       </lr:LoginRequest>" +
>                 "   </r:Data>" +
>                 "</r:Request>";
>
>         RequestDocument doc =
RequestDocument.Factory.parse(instanceSource);
>
>         RequestDataType[] data =
> doc.getRequest().getData().getRequestDataArray();
>         assertEquals(data.length, 1);
>         assertTrue("request data should be instanceof LoginRequestType",
> data[0] instanceof LoginRequestType);
>         assertEquals(new
> QName("http://parsys.parsec.es/xmlbind/request/login", "LoginRequest"),
> data[0].newCursor().getName());
>         assertEquals("ramos", ((LoginRequestType)data[0]).getUserId());
>     }
> ====
>
>
>
> David
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>



- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: Problem with variable content containers ( lengthy )

Posted by Javier Ramos <ra...@parsec.es>.
Hi, David,

    Thanks for taking the time to test, I also recently made it work and was
about to send a notification to this mailing list. Of course you can add the
code to the xmlbeans test suite.

    I am a newbie to XMLBeans and having a very good experience with
xmlbeans, even admitting that I did not take enough time to read all the
documentation yet. Initially I tried to use JAXB implementations, but I find
the xmlbeans approach much more flexible and superior.

    I am starting the development of a web application framework
implementing the MVC pattern, doing the V with Cocoon, and the C with a
servlet implementing the Front Contoller pattern and containing a dispatcher
for a sereies of controllers for the different actions of the application.
The communication between Cocoon presentation layer and the front controler
is via XML, and I use an  xmlbinding technology to be able to serialize and
deserialize between Java and XML. This way I get request / response Java
objects from Schema definitions without having to write a line of code.

    Everything is setup now using XMLBeans as the java xml binding
technology. In your opinion, if I am to deploy for production a new
application based in this setup in approximately 6 months, should I focus on
XMLBeans version 1 or 2?

    Right now I am dealing with version 1... Somewhere I read that version
two will be very different. What kind of benefits can it provide?

    Also: Some time I will want to try the approach number 3 to creating
variable content containers in schema definitions described in the document
referenced in my previous post. Do you think it is possible to implement
that with XMLBeans?

    In that case, all the elements in the variable content container have
the same element name, but different xsi:type. I suppose I can somehow get
this information to be able to process element according to its type... I
will have to play more with the API. Any clue? If I get this thing working
also, are you interested in receiving a test case?

    Best regards,

        Javier Ramos


----- Original Message ----- 
From: "David Bau" <da...@bea.com>
To: <xm...@xml.apache.org>
Sent: Wednesday, November 19, 2003 1:20 PM
Subject: Re: Problem with variable content containers ( lengthy )


> Hello Javier,
>
>
> Your code works!  It did include a few typos.
>
> XMLBeans should work fine here - it is a basic case of element and type
> substitution.  (If it didn't it would be a bug in XMLBeans...) Can I add
> your test case to the xmlbeans regression test suite?
>
> Now, details.  I did need to change a few things in your schemas and XML
doc
> because the schemas didn't actually compile as you pasted them - there
were
> a couple issues where the schemas used an undefined namespace prefix, and
> another issue where you referenced an undefined element because of a
> namespace prefix mixup. Here is the actual schema that I compiled and ran:
>
>
> File 1:
>
> ====
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     xmlns:r="http://waf.parsec.es/xmlbind/request"
>     targetNamespace="http://waf.parsec.es/xmlbind/request"
>     elementFormDefault="qualified"
>     attributeFormDefault="unqualified">
>
> <xs:complexType name="RequestDataType">
>     <xs:attribute name="creationDate" type="xs:date"/>
> </xs:complexType>
>
> <xs:element name="RequestData" abstract="true" type="r:RequestDataType"/>
>
> <xs:complexType name="Data">
> <xs:sequence>
>     <xs:element ref="r:RequestData" maxOccurs="unbounded"/>
> </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="Request">
> <xs:sequence>
>     <xs:element name="Data" type="r:Data" minOccurs="1" maxOccurs="1"/>
> </xs:sequence>
> </xs:complexType>
>
> <xs:element name="Request" type="r:Request"/>
>
> </xs:schema>
> ====
>
>
> File 2:
> ====
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:rq="http://waf.parsec.es/xmlbind/request"
> xmlns:r="http://parsys.parsec.es/xmlbind/request/login"
> targetNamespace="http://parsys.parsec.es/xmlbind/request/login"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified">
>
> <xs:import
> namespace="http://waf.parsec.es/xmlbind/request/data"
> />
>
> <xs:complexType name="LoginRequestType">
> <xs:complexContent>
>     <xs:extension base="rq:RequestDataType">
>         <xs:sequence>
>             <xs:element name="UserId" type="xs:string"/>
>         <xs:element name="Password" type="xs:string"/>
>     </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> <xs:element name="LoginRequest" type="r:LoginRequestType"
> substitutionGroup="rq:RequestData"/>
>
> </xs:schema>
> ====
>
>
>
> The test case follows, which also fixes a namespace issue:
>
>
> ====
>     // Thanks to Javier Ramos
>     public void test5() throws Exception
>     {
>         String instanceSource =
>                 "<r:Request xmlns:r='http://waf.parsec.es/xmlbind/request'
> xmlns:lr='http://parsys.parsec.es/xmlbind/request/login'>" +
>                 "   <r:Data>" +
>                 "       <lr:LoginRequest>" +
>                 "           <lr:UserId>ramos</lr:UserId>" +
>                 "           <lr:Password>pass</lr:Password>" +
>                 "       </lr:LoginRequest>" +
>                 "   </r:Data>" +
>                 "</r:Request>";
>
>         RequestDocument doc =
RequestDocument.Factory.parse(instanceSource);
>
>         RequestDataType[] data =
> doc.getRequest().getData().getRequestDataArray();
>         assertEquals(data.length, 1);
>         assertTrue("request data should be instanceof LoginRequestType",
> data[0] instanceof LoginRequestType);
>         assertEquals(new
> QName("http://parsys.parsec.es/xmlbind/request/login", "LoginRequest"),
> data[0].newCursor().getName());
>         assertEquals("ramos", ((LoginRequestType)data[0]).getUserId());
>     }
> ====
>
>
>
> David
>
>
> - ---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
>



- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: Problem with variable content containers ( lengthy )

Posted by David Bau <da...@bea.com>.
Hello Javier,


Your code works!  It did include a few typos.

XMLBeans should work fine here - it is a basic case of element and type
substitution.  (If it didn't it would be a bug in XMLBeans...) Can I add
your test case to the xmlbeans regression test suite?

Now, details.  I did need to change a few things in your schemas and XML doc
because the schemas didn't actually compile as you pasted them - there were
a couple issues where the schemas used an undefined namespace prefix, and
another issue where you referenced an undefined element because of a
namespace prefix mixup. Here is the actual schema that I compiled and ran:


File 1:

====
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:r="http://waf.parsec.es/xmlbind/request"
    targetNamespace="http://waf.parsec.es/xmlbind/request"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

<xs:complexType name="RequestDataType">
    <xs:attribute name="creationDate" type="xs:date"/>
</xs:complexType>

<xs:element name="RequestData" abstract="true" type="r:RequestDataType"/>

<xs:complexType name="Data">
<xs:sequence>
    <xs:element ref="r:RequestData" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="Request">
<xs:sequence>
    <xs:element name="Data" type="r:Data" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>

<xs:element name="Request" type="r:Request"/>

</xs:schema>
====


File 2:
====
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:rq="http://waf.parsec.es/xmlbind/request"
xmlns:r="http://parsys.parsec.es/xmlbind/request/login"
targetNamespace="http://parsys.parsec.es/xmlbind/request/login"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:import
namespace="http://waf.parsec.es/xmlbind/request/data"
/>

<xs:complexType name="LoginRequestType">
<xs:complexContent>
    <xs:extension base="rq:RequestDataType">
        <xs:sequence>
            <xs:element name="UserId" type="xs:string"/>
        <xs:element name="Password" type="xs:string"/>
    </xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="LoginRequest" type="r:LoginRequestType"
substitutionGroup="rq:RequestData"/>

</xs:schema>
====



The test case follows, which also fixes a namespace issue:


====
    // Thanks to Javier Ramos
    public void test5() throws Exception
    {
        String instanceSource =
                "<r:Request xmlns:r='http://waf.parsec.es/xmlbind/request'
xmlns:lr='http://parsys.parsec.es/xmlbind/request/login'>" +
                "   <r:Data>" +
                "       <lr:LoginRequest>" +
                "           <lr:UserId>ramos</lr:UserId>" +
                "           <lr:Password>pass</lr:Password>" +
                "       </lr:LoginRequest>" +
                "   </r:Data>" +
                "</r:Request>";

        RequestDocument doc = RequestDocument.Factory.parse(instanceSource);

        RequestDataType[] data =
doc.getRequest().getData().getRequestDataArray();
        assertEquals(data.length, 1);
        assertTrue("request data should be instanceof LoginRequestType",
data[0] instanceof LoginRequestType);
        assertEquals(new
QName("http://parsys.parsec.es/xmlbind/request/login", "LoginRequest"),
data[0].newCursor().getName());
        assertEquals("ramos", ((LoginRequestType)data[0]).getUserId());
    }
====



David


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Re: Problem with variable content containers ( lengthy )

Posted by David Bau <da...@bea.com>.
Hello Javier,


Your code works!  It did include a few typos.

XMLBeans should work fine here - it is a basic case of element and type
substitution.  (If it didn't it would be a bug in XMLBeans...) Can I add
your test case to the xmlbeans regression test suite?

Now, details.  I did need to change a few things in your schemas and XML doc
because the schemas didn't actually compile as you pasted them - there were
a couple issues where the schemas used an undefined namespace prefix, and
another issue where you referenced an undefined element because of a
namespace prefix mixup. Here is the actual schema that I compiled and ran:


File 1:

====
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:r="http://waf.parsec.es/xmlbind/request"
    targetNamespace="http://waf.parsec.es/xmlbind/request"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

<xs:complexType name="RequestDataType">
    <xs:attribute name="creationDate" type="xs:date"/>
</xs:complexType>

<xs:element name="RequestData" abstract="true" type="r:RequestDataType"/>

<xs:complexType name="Data">
<xs:sequence>
    <xs:element ref="r:RequestData" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="Request">
<xs:sequence>
    <xs:element name="Data" type="r:Data" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>

<xs:element name="Request" type="r:Request"/>

</xs:schema>
====


File 2:
====
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:rq="http://waf.parsec.es/xmlbind/request"
xmlns:r="http://parsys.parsec.es/xmlbind/request/login"
targetNamespace="http://parsys.parsec.es/xmlbind/request/login"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:import
namespace="http://waf.parsec.es/xmlbind/request/data"
/>

<xs:complexType name="LoginRequestType">
<xs:complexContent>
    <xs:extension base="rq:RequestDataType">
        <xs:sequence>
            <xs:element name="UserId" type="xs:string"/>
        <xs:element name="Password" type="xs:string"/>
    </xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="LoginRequest" type="r:LoginRequestType"
substitutionGroup="rq:RequestData"/>

</xs:schema>
====



The test case follows, which also fixes a namespace issue:


====
    // Thanks to Javier Ramos
    public void test5() throws Exception
    {
        String instanceSource =
                "<r:Request xmlns:r='http://waf.parsec.es/xmlbind/request'
xmlns:lr='http://parsys.parsec.es/xmlbind/request/login'>" +
                "   <r:Data>" +
                "       <lr:LoginRequest>" +
                "           <lr:UserId>ramos</lr:UserId>" +
                "           <lr:Password>pass</lr:Password>" +
                "       </lr:LoginRequest>" +
                "   </r:Data>" +
                "</r:Request>";

        RequestDocument doc = RequestDocument.Factory.parse(instanceSource);

        RequestDataType[] data =
doc.getRequest().getData().getRequestDataArray();
        assertEquals(data.length, 1);
        assertTrue("request data should be instanceof LoginRequestType",
data[0] instanceof LoginRequestType);
        assertEquals(new
QName("http://parsys.parsec.es/xmlbind/request/login", "LoginRequest"),
data[0].newCursor().getName());
        assertEquals("ramos", ((LoginRequestType)data[0]).getUserId());
    }
====



David


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/