2 messages in org.apache.xmlbeans.userRe: RE: Abstract Types
FromSent OnAttachments
Radu Preotiuc-PietroAug 30, 2006 9:32 am 
Satish KumarAug 31, 2006 12:50 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: RE: Abstract TypesActions...
From:Satish Kumar (sati@rediffmail.com)
Date:Aug 31, 2006 12:50:04 am
List:org.apache.xmlbeans.user

  Thanks Radu, it works now !!!!

On Wed, 30 Aug 2006 Radu Preotiuc-Pietro wrote :

First, let me assume that your Schema declares "AbstractClass" as the substitutionGroup for "classA" and "classB" and not "AbstractElement" like stated in your message. Then, you would write the following code:

RootDocument doc = RootDocument.Factory.newInstance(); RootDocument.Root root = doc.addNewRoot(); XmlObject xmlObject = root.addNewAbstractClass(); xmlObject = xmlObject.substitute( ClassADocument.type.getDocumentElementName(), ClassAType.type); // You can now add stuff to xmlObject

Now the "doc" object will contain the document in the format you want.

The idea is that you need to use the method .substitute() to create a document that uses substitution groups. XmlBeans doesn't look at the fact that the element is abstract or that it has substitutions but instead uses the simpler rule that "you need to call .substitute() if you want to enable substitutions".

Radu

Hi,

Need some help in solving problems of abstract types. I have the following elements:

<xs:element name="Root"> <xs:complexType> <xs:sequence> <xs:element ref="AbstractClass"/> </xs:sequence> </xs:complexType> </xs:element>

<element name="AbstractClass" abstract="true">

<element name="classA" type="ClassAType" substitutionGroup="AbstractElement">

<element name="classB" type="ClassBType" substitutionGroup="AbstractElement">

I need an output XML of the form

<root> <classA>...........</classA> </root>

but i get the following:

<root> <AbstractClass> <classA>...........</classA> </AbstractClass> </root>

In the java code i have the following options

a) root.addNewAbstractClass(); b) root.setAbstractClass(XmlObject xmlObject);

I want to get only the implementation of the "AbstractClass" as the sub-element of the "Root" element, how is it possible to achieve this.

Thanks in advance,

Cheers, Satish