xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Javier Ramos" <ra...@parsec.es>
Subject Problem with variable content containers ( lengthy )
Date Tue, 18 Nov 2003 10:45:06 GMT
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. 



Mime
View raw message