Unable to load mixed content when loading an ecore model derived from an xml schema [message #604369] |
Tue, 22 September 2009 17:44 |
Dhiraj Messages: 18 Registered: July 2009 |
Junior Member |
|
|
I have the following sample xsd:-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.org/NewXMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://www.example.org/NewXMLSchema">
<complexType mixed="true" name="PersonType">
<sequence>
<any processContents="lax" namespace="##any" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="name" type="string" />
</complexType>
<element name="Person" type="tns:PersonType"></element>
</schema>
And using the EMF Project I created an ecore out of this xsd and
added a derived feature 'classification' which would be assigned
the value from the text node of the Person element. The ecore for
this derived attribute is like this:-
<eStructuralFeatures xsi:type="ecore:EAttribute" name="classification" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String"
volatile="true" transient="true" defaultValueLiteral="" derived="true">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value=":3"/>
<details key="kind" value="simple"/>
</eAnnotations>
</eStructuralFeatures>
I have attached the complete ecore file with this post (filename: schema.ecore)
Then I was trying to load the following model file (xml file):-
<?xml version="1.0" encoding="UTF-8"?>
<schema:Person xmlns:schema="http://www.example.org/NewXMLSchema" name="Dhiraj">Dhiraj KUmar<schema:Person name="Manoj"/></schema:Person>
using the following Junit test, but for some reason the 'mixed' attribute of
the PersonType EObject was not being loaded with the correct values and as
a result the 'classification' feature was having an empty value. Following is
the code to load the model file:-
public class ModelLoadingTest extends TestCase {
public void testLoading() {
URI composite2xURI = URI.createPlatformPluginURI(
"/PersonEcore/test/Person.schema", true);
ResourceSet rset = new ResourceSetImpl();
rset.getPackageRegistry().put("http://www.example.org/NewXMLSchema",
getPersonEPackage());
rset.getPackageRegistry().put("http://www.eclipse.org/xsd/2002/XSD",
XSDPackage.eINSTANCE);
XMLResourceImpl c2xRes = new XMLResourceImpl(composite2xURI);
Map<Object, Object> defaultLoadOptions = c2xRes.getDefaultLoadOptions();
defaultLoadOptions.put(XMLResource.OPTION_RECORD_UNKNOWN_FEA TURE,
Boolean.TRUE);
defaultLoadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA ,
Boolean.TRUE);
rset.getResources().add(c2xRes);
try {
c2xRes.load(null);
System.out.println("loaded the resource correctly...");
EObject person = c2xRes.getContents().get(0);
person.getClass();
} catch (IOException e) {
e.printStackTrace();
}
}
public EPackage getPersonEPackage() {
EPackage composite2xPkg = null;
ResourceSet rset = new ResourceSetImpl();
Resource res = rset
.createResource(URI.createPlatformPluginURI(
"/PersonEcore/model/schema.ecore", true)); //$NON-NLS-1$ //$NON-NLS-2$
try {
res.load(null);
composite2xPkg = (EPackage) res.getContents().get(0);
} catch (IOException e) {
e.printStackTrace();
}
return composite2xPkg;
}
}
Do I need to pass some other options while loading such resources?
|
|
|
Powered by
FUDForum. Page generated in 0.04114 seconds