You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Richard J Cardone <ri...@us.ibm.com> on 2008/10/24 01:09:37 UTC
Problem with list of derived types
Hi,
I'm having a problem using lists of derived types under Xmlbeans 2.4.0.
Basically, I'm trying to define a list of base type and populate that list
with instances of derived types. For example, given a schema that
contains complex types of Parent, Child1, and Child2, where Parent is
abstract and extended by Child1 and Child2, I define a list of child
elements using the Parent type as follows:
<xs:complexType name="Children">
<xs:sequence>
<xs:element name="item" type="Parent"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
I then create a Child1 instance, set its required content, validate it,
and add it to an Xmlbeans-generated ListChildren instance without error.
The ListChildren instance, however, fails validation because the required
Child1 attributes and subelements are not found, even though I set them
and the Child1 instance's validate method returned true. Moreover, when I
save the whole document, the output looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<cfn:DOC xmlns:cfn="http://cfnxml" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<items>
<item xsi:type="cfn:Child1"/>
</items>
</cfn:DOC>
I don't know why content from the Child1 instance is missing from the
output. To recap, my two questions are (1) Why does validation fail in
the Children list even though the Child1 instance validation independently
succeeds, and (2) Why does save() not output all assigned Child1 content
as part of item element?
Any help is appreciated,
Rich
RE: Problem with list of derived types
Posted by Radu Preotiuc-Pietro <ra...@oracle.com>.
Well, it seems like your two problems really are the same thing: you are not setting values on the correct "Child" element. If you can share your code, we may be able to spot the error, but I can assure you that it is possible to do what you want.
Radu
________________________________
From: Richard J Cardone [mailto:richcar@us.ibm.com]
Sent: Thursday, October 23, 2008 4:10 PM
To: user@xmlbeans.apache.org
Subject: Problem with list of derived types
Hi,
I'm having a problem using lists of derived types under Xmlbeans 2.4.0. Basically, I'm trying to define a list of base type and populate that list with instances of derived types. For example, given a schema that contains complex types of Parent, Child1, and Child2, where Parent is abstract and extended by Child1 and Child2, I define a list of child elements using the Parent type as follows:
<xs:complexType name="Children">
<xs:sequence>
<xs:element name="item" type="Parent" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
I then create a Child1 instance, set its required content, validate it, and add it to an Xmlbeans-generated ListChildren instance without error. The ListChildren instance, however, fails validation because the required Child1 attributes and subelements are not found, even though I set them and the Child1 instance's validate method returned true. Moreover, when I save the whole document, the output looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<cfn:DOC xmlns:cfn="http://cfnxml <http://cfnxml/> " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance <http://www.w3.org/2001/XMLSchema-instance> ">
<items>
<item xsi:type="cfn:Child1"/>
</items>
</cfn:DOC>
I don't know why content from the Child1 instance is missing from the output. To recap, my two questions are (1) Why does validation fail in the Children list even though the Child1 instance validation independently succeeds, and (2) Why does save() not output all assigned Child1 content as part of item element?
Any help is appreciated,
Rich
RE: Problem with list of derived types
Posted by richcar <ri...@us.ibm.com>.
Radu,
Thanks for taking a look at the problem. I'll test your solution as soon as
I get a chance.
Rich
--
View this message in context: http://www.nabble.com/Problem-with-list-of-derived-types-tp20151202p20564191.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org