Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How do I include an XML schema in an EMF model?
How do I include an XML schema in an EMF model? [message #391028] Wed, 09 February 2005 20:48 Go to next message
Eclipse UserFriend
Originally posted by: john.sipher.ssaglobal.com

I want to wrap an XML schema inside an XML document that will be represented
by an EMF model, and I'd like to have the schema part of the document
processed by XSD when I load the parent document into my model.

For example, assume I have a schema that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://mydomain/test"
xmlns="http://mydomain/test"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:complexType name="RootElement">
<xs:sequence>
<xs:element name="properties" type="ConfigProperty" minOccurs="0"
maxOccurs="unbounded"/>
<xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConfigProperty">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

If I use that schema to generate an EMF model, I think the generated model
ought to be able to process a document that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<test:RootElement xmlns:test="http://mydomain/test">
<properties>
<name>name1</name>
<value>value1</value>
</properties>
<xs:schema targetNamespace="http://mydomain/test"
xmlns="http://mydomain/test"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<xs:complexType name="RootElement">
<xs:sequence>
<xs:element name="properties" type="ConfigProperty" minOccurs="0"
maxOccurs="unbounded"/>
<xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConfigProperty">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</test:RootElement>

In other words, the <xs:schema> element ought to be legal content for the
<xs:any> element in my schema. However, when I try to load the document it
complains about Feature 'schema' not found. (model/test.test, 10, -1).

The code that tries to load the document looks like this:

XSDPackageImpl.init();
TestPackageImpl.init();
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*",new
TestResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;

Any suggestions?

Thanks,
John Sipher
Re: How do I include an XML schema in an EMF model? [message #391031 is a reply to message #391028] Wed, 09 February 2005 21:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
John,

This is much easier said than done. A schema model instance must be
constructed from a DOM, so you need to create a DOM when parsing and
then use that to create the XSDSchema. Similarly, when serializing, you
need to get the DOM from the XSDSchema and serialize that. The folks
doing a WSDL model need to solve this problem, but that's been done by
making the WSDL model work much like the XSD model. Probably is you
look at how XSDResourceImpl implements doSave and doLoad, it will be
more clear how it works (and that you have a hard problem to solve.).


John Sipher wrote:

>I want to wrap an XML schema inside an XML document that will be represented
>by an EMF model, and I'd like to have the schema part of the document
>processed by XSD when I load the parent document into my model.
>
>For example, assume I have a schema that looks like this:
>
><?xml version="1.0" encoding="UTF-8"?>
><xs:schema targetNamespace="http://mydomain/test"
> xmlns="http://mydomain/test"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="unqualified" attributeFormDefault="unqualified">
> <xs:complexType name="RootElement">
> <xs:sequence>
> <xs:element name="properties" type="ConfigProperty" minOccurs="0"
>maxOccurs="unbounded"/>
> <xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="ConfigProperty">
> <xs:sequence>
> <xs:element name="name" type="xs:string"/>
> <xs:element name="value" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
></xs:schema>
>
>If I use that schema to generate an EMF model, I think the generated model
>ought to be able to process a document that looks like this:
><?xml version="1.0" encoding="UTF-8"?>
><test:RootElement xmlns:test="http://mydomain/test">
> <properties>
> <name>name1</name>
> <value>value1</value>
> </properties>
> <xs:schema targetNamespace="http://mydomain/test"
> xmlns="http://mydomain/test"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="unqualified"
>attributeFormDefault="unqualified">
> <xs:complexType name="RootElement">
> <xs:sequence>
> <xs:element name="properties" type="ConfigProperty" minOccurs="0"
>maxOccurs="unbounded"/>
> <xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="ConfigProperty">
> <xs:sequence>
> <xs:element name="name" type="xs:string"/>
> <xs:element name="value" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
></test:RootElement>
>
>In other words, the <xs:schema> element ought to be legal content for the
><xs:any> element in my schema. However, when I try to load the document it
>complains about Feature 'schema' not found. (model/test.test, 10, -1).
>
>The code that tries to load the document looks like this:
>
> XSDPackageImpl.init();
> TestPackageImpl.init();
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*",new
>TestResourceFactoryImpl());
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;
>
>Any suggestions?
>
>Thanks,
>John Sipher
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How do I include an XML schema in an EMF model? [message #391049 is a reply to message #391031] Thu, 10 February 2005 15:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.sipher.ssaglobal.com

Ed,

Thanks for the quick response. For my purposes the solution is relatively
easy now that I know I'm not missing something easy in the original
approach. I did run across something that didn't work as I thought it
should from reading the XSD FAQ.

I think I should be able to do this to get empty resources that I can load.
// initalize packages
XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();
// set up resource registry

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
w XSDResourceFactoryImpl());
// get "empty" resources
ResourceSet resourceSet = new ResourceSetImpl();
TestResourceImpl testResource =
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
XSDResourceImpl xsdResource =
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));

In both cases resourceSet.createResource() returns null, and I'm not sure
why. I traced into it and it looks as if the resource factory registry
hasn't been initialized yet.

John

The "solution" to the original problem follows. Please let me know if
anyone sees problems with it (exception handling obviously needs to be
added).

String modelURL = args[0];
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new FileInputStream(modelURL));

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Transformer transformer =
TransformerFactory.newInstance().newTransformer();

XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
w XSDResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
// TestResourceImpl testResource =
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
// XSDResourceImpl xsdResource =
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
TestResourceImpl testResource = new
TestResourceImpl(URI.createURI("*.test"));
XSDResourceImpl xsdResource = new
XSDResourceImpl(URI.createURI("*.xsd"));
resourceSet.getResources().add(testResource);
resourceSet.getResources().add(xsdResource);

// get the embedded schema, load it into an XSDSchema instance, and add
it to the xsd resource
Element schemaElement =
(Element)document.getDocumentElement().getElementsByTagNameN S( "http://www.w3
..org/2001/XMLSchema","schema").item(0);
DOMResult domResult = new DOMResult(builder.newDocument());
transformer.transform(new DOMSource(schemaElement),domResult);
XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
schema.setElement(((Document)domResult.getNode()).getDocumen tElement());
xsdResource.getContents().add(schema);

// remove the schema from the original document and load the remainder
into the test resource.
document.getDocumentElement().removeChild(schemaElement);
transformer.transform(new DOMSource(document),new StreamResult(baos));
testResource.load(new
ByteArrayInputStream(baos.toByteArray()),resourceSet.getLoad Options());

"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cudtig$22c$1@www.eclipse.org...
> John,
>
> This is much easier said than done. A schema model instance must be
> constructed from a DOM, so you need to create a DOM when parsing and
> then use that to create the XSDSchema. Similarly, when serializing, you
> need to get the DOM from the XSDSchema and serialize that. The folks
> doing a WSDL model need to solve this problem, but that's been done by
> making the WSDL model work much like the XSD model. Probably is you
> look at how XSDResourceImpl implements doSave and doLoad, it will be
> more clear how it works (and that you have a hard problem to solve.).
>
>
> John Sipher wrote:
>
> >I want to wrap an XML schema inside an XML document that will be
represented
> >by an EMF model, and I'd like to have the schema part of the document
> >processed by XSD when I load the parent document into my model.
> >
> >For example, assume I have a schema that looks like this:
> >
> ><?xml version="1.0" encoding="UTF-8"?>
> ><xs:schema targetNamespace="http://mydomain/test"
> > xmlns="http://mydomain/test"
> > xmlns:xs="http://www.w3.org/2001/XMLSchema"
> > elementFormDefault="unqualified" attributeFormDefault="unqualified">
> > <xs:complexType name="RootElement">
> > <xs:sequence>
> > <xs:element name="properties" type="ConfigProperty" minOccurs="0"
> >maxOccurs="unbounded"/>
> > <xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
> > </xs:sequence>
> > </xs:complexType>
> > <xs:complexType name="ConfigProperty">
> > <xs:sequence>
> > <xs:element name="name" type="xs:string"/>
> > <xs:element name="value" type="xs:string"/>
> > </xs:sequence>
> > </xs:complexType>
> ></xs:schema>
> >
> >If I use that schema to generate an EMF model, I think the generated
model
> >ought to be able to process a document that looks like this:
> ><?xml version="1.0" encoding="UTF-8"?>
> ><test:RootElement xmlns:test="http://mydomain/test">
> > <properties>
> > <name>name1</name>
> > <value>value1</value>
> > </properties>
> > <xs:schema targetNamespace="http://mydomain/test"
> > xmlns="http://mydomain/test"
> > xmlns:xs="http://www.w3.org/2001/XMLSchema"
> > elementFormDefault="unqualified"
> >attributeFormDefault="unqualified">
> > <xs:complexType name="RootElement">
> > <xs:sequence>
> > <xs:element name="properties" type="ConfigProperty" minOccurs="0"
> >maxOccurs="unbounded"/>
> > <xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
> > </xs:sequence>
> > </xs:complexType>
> > <xs:complexType name="ConfigProperty">
> > <xs:sequence>
> > <xs:element name="name" type="xs:string"/>
> > <xs:element name="value" type="xs:string"/>
> > </xs:sequence>
> > </xs:complexType>
> > </xs:schema>
> ></test:RootElement>
> >
> >In other words, the <xs:schema> element ought to be legal content for the
> ><xs:any> element in my schema. However, when I try to load the document
it
> >complains about Feature 'schema' not found. (model/test.test, 10, -1).
> >
> >The code that tries to load the document looks like this:
> >
> > XSDPackageImpl.init();
> > TestPackageImpl.init();
> >
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*",new
> >TestResourceFactoryImpl());
> > ResourceSet resourceSet = new ResourceSetImpl();
> > resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;
> >
> >Any suggestions?
> >
> >Thanks,
> >John Sipher
> >
> >
> >
> >
Re: How do I include an XML schema in an EMF model? [message #391050 is a reply to message #391049] Thu, 10 February 2005 17:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060302030506000303070109
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

John,

You should register "test" and "xsd", not "*.test" and "*.xsd". Note also that if the schema contains schemaLocation="..." where the ... is a relative path, it's important that the URI of the containing resource be an absolute path so that relative location can be interpreted properly. In that case "*.xsd" would not be so good and you might want to take the name of the actual location of the bigger file (modelURL) and append .xsd to it to create your "fake" XSD URI.

I also made a comment line below about the add of the resource being unnecessary since the createResource will already have added it...


John Sipher wrote:

>Ed,
>
>Thanks for the quick response. For my purposes the solution is relatively
>easy now that I know I'm not missing something easy in the original
>approach. I did run across something that didn't work as I thought it
>should from reading the XSD FAQ.
>
>I think I should be able to do this to get empty resources that I can load.
> // initalize packages
> XSDPackage.eINSTANCE.getEFactoryInstance();
> TestPackage.eINSTANCE.getEFactoryInstance();
> // set up resource registry
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
>ew TestResourceFactoryImpl());
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
>w XSDResourceFactoryImpl());
> // get "empty" resources
> ResourceSet resourceSet = new ResourceSetImpl();
> TestResourceImpl testResource =
>(TestResourceImpl)resourceSet.createResource(URI.createURI( "*.test"));
> XSDResourceImpl xsdResource =
>(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
>
>In both cases resourceSet.createResource() returns null, and I'm not sure
>why. I traced into it and it looks as if the resource factory registry
>hasn't been initialized yet.
>
>John
>
>The "solution" to the original problem follows. Please let me know if
>anyone sees problems with it (exception handling obviously needs to be
>added).
>
> String modelURL = args[0];
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> factory.setNamespaceAware(true);
> DocumentBuilder builder = factory.newDocumentBuilder();
> Document document = builder.parse(new FileInputStream(modelURL));
>
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> Transformer transformer =
>TransformerFactory.newInstance().newTransformer();
>
> XSDPackage.eINSTANCE.getEFactoryInstance();
> TestPackage.eINSTANCE.getEFactoryInstance();
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
>ew TestResourceFactoryImpl());
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
>w XSDResourceFactoryImpl());
> ResourceSet resourceSet = new ResourceSetImpl();
>// TestResourceImpl testResource =
>(TestResourceImpl)resourceSet.createResource(URI.createURI( "*.test"));
>// XSDResourceImpl xsdResource =
>(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
> TestResourceImpl testResource = new
>TestResourceImpl(URI.createURI("*.test"));
> XSDResourceImpl xsdResource = new
>XSDResourceImpl(URI.createURI("*.xsd"));
> resourceSet.getResources().add(testResource);
> resourceSet.getResources().add(xsdResource);
>
>
The created resource is already added, so this is a no-op.

> // get the embedded schema, load it into an XSDSchema instance, and add
>it to the xsd resource
> Element schemaElement =
> (Element)document.getDocumentElement().getElementsByTagNameN S( "http://www.w3
>.org/2001/XMLSchema","schema").item(0);
> DOMResult domResult = new DOMResult(builder.newDocument());
> transformer.transform(new DOMSource(schemaElement),domResult);
> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
> schema.setElement(((Document)domResult.getNode()).getDocumen tElement());
> xsdResource.getContents().add(schema);
>
> // remove the schema from the original document and load the remainder
>into the test resource.
> document.getDocumentElement().removeChild(schemaElement);
> transformer.transform(new DOMSource(document),new StreamResult(baos));
> testResource.load(new
> ByteArrayInputStream(baos.toByteArray()),resourceSet.getLoad Options());
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cudtig$22c$1@www.eclipse.org...
>
>
>>John,
>>
>>This is much easier said than done. A schema model instance must be
>>constructed from a DOM, so you need to create a DOM when parsing and
>>then use that to create the XSDSchema. Similarly, when serializing, you
>>need to get the DOM from the XSDSchema and serialize that. The folks
>>doing a WSDL model need to solve this problem, but that's been done by
>>making the WSDL model work much like the XSD model. Probably is you
>>look at how XSDResourceImpl implements doSave and doLoad, it will be
>>more clear how it works (and that you have a hard problem to solve.).
>>
>>
>>John Sipher wrote:
>>
>>
>>
>>>I want to wrap an XML schema inside an XML document that will be
>>>
>>>
>represented
>
>
>>>by an EMF model, and I'd like to have the schema part of the document
>>>processed by XSD when I load the parent document into my model.
>>>
>>>For example, assume I have a schema that looks like this:
>>>
>>><?xml version="1.0" encoding="UTF-8"?>
>>><xs:schema targetNamespace="http://mydomain/test"
>>>xmlns="http://mydomain/test"
>>>xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>>elementFormDefault="unqualified" attributeFormDefault="unqualified">
>>><xs:complexType name="RootElement">
>>> <xs:sequence>
>>> <xs:element name="properties" type="ConfigProperty" minOccurs="0"
>>>maxOccurs="unbounded"/>
>>> <xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
>>> </xs:sequence>
>>></xs:complexType>
>>><xs:complexType name="ConfigProperty">
>>> <xs:sequence>
>>> <xs:element name="name" type="xs:string"/>
>>> <xs:element name="value" type="xs:string"/>
>>> </xs:sequence>
>>></xs:complexType>
>>></xs:schema>
>>>
>>>If I use that schema to generate an EMF model, I think the generated
>>>
>>>
>model
>
>
>>>ought to be able to process a document that looks like this:
>>><?xml version="1.0" encoding="UTF-8"?>
>>><test:RootElement xmlns:test="http://mydomain/test">
>>> <properties>
>>> <name>name1</name>
>>> <value>value1</value>
>>> </properties>
>>> <xs:schema targetNamespace="http://mydomain/test"
>>> xmlns="http://mydomain/test"
>>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>> elementFormDefault="unqualified"
>>>attributeFormDefault="unqualified">
>>> <xs:complexType name="RootElement">
>>> <xs:sequence>
>>> <xs:element name="properties" type="ConfigProperty" minOccurs="0"
>>>maxOccurs="unbounded"/>
>>> <xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
>>> </xs:sequence>
>>> </xs:complexType>
>>> <xs:complexType name="ConfigProperty">
>>> <xs:sequence>
>>> <xs:element name="name" type="xs:string"/>
>>> <xs:element name="value" type="xs:string"/>
>>> </xs:sequence>
>>> </xs:complexType>
>>> </xs:schema>
>>></test:RootElement>
>>>
>>>In other words, the <xs:schema> element ought to be legal content for the
>>><xs:any> element in my schema. However, when I try to load the document
>>>
>>>
>it
>
>
>>>complains about Feature 'schema' not found. (model/test.test, 10, -1).
>>>
>>>The code that tries to load the document looks like this:
>>>
>>> XSDPackageImpl.init();
>>> TestPackageImpl.init();
>>>
>>>
>>>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*",new
>
>
>>>TestResourceFactoryImpl());
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>> resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;
>>>
>>>Any suggestions?
>>>
>>>Thanks,
>>>John Sipher
>>>
>>>
>>>
>>>
>>>
>>>
>
>
>
>


--------------060302030506000303070109
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
John,<br>
<pre wrap="">You should register "test" and "xsd", not "*.test" and "*.xsd". Note also that if the schema contains schemaLocation="..." where the ... is a relative path, it's important that the URI of the containing resource be an absolute path so that relative location can be interpreted properly. In that case "*.xsd" would not be so good and you might want to take the name of the actual location of the bigger file (modelURL) and append .xsd to it to create your "fake" XSD URI.

I also made a comment line below about the add of the resource being unnecessary since the createResource will already have added it...
</pre>
<br>
John Sipher wrote:
<blockquote cite="midcug16k$snl$1@www.eclipse.org" type="cite">
<pre wrap="">Ed,

Thanks for the quick response. For my purposes the solution is relatively
easy now that I know I'm not missing something easy in the original
approach. I did run across something that didn't work as I thought it
should from reading the XSD FAQ.

I think I should be able to do this to get empty resources that I can load.
// initalize packages
XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();
// set up resource registry

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
w XSDResourceFactoryImpl());
// get "empty" resources
ResourceSet resourceSet = new ResourceSetImpl();
TestResourceImpl testResource =
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
XSDResourceImpl xsdResource =
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));

In both cases resourceSet.createResource() returns null, and I'm not sure
why. I traced into it and it looks as if the resource factory registry
hasn't been initialized yet.

John

The "solution" to the original problem follows. Please let me know if
anyone sees problems with it (exception handling obviously needs to be
added).

String modelURL = args[0];
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new FileInputStream(modelURL));

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Transformer transformer =
TransformerFactory.newInstance().newTransformer();

XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
w XSDResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
// TestResourceImpl testResource =
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
// XSDResourceImpl xsdResource =
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
TestResourceImpl testResource = new
TestResourceImpl(URI.createURI("*.test"));
XSDResourceImpl xsdResource = new
XSDResourceImpl(URI.createURI("*.xsd"));
resourceSet.getResources().add(testResource);
resourceSet.getResources().add(xsdResource);
</pre>
</blockquote>
The created resource is already added, so this is a no-op.<br>
<blockquote cite="midcug16k$snl$1@www.eclipse.org" type="cite">
<pre wrap="">
// get the embedded schema, load it into an XSDSchema instance, and add
it to the xsd resource
Element schemaElement =
(Element)document.getDocumentElement().getElementsByTagNameN S( <a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3
..org/2001/XMLSchema"</a>,"schema").item(0);
DOMResult domResult = new DOMResult(builder.newDocument());
transformer.transform(new DOMSource(schemaElement),domResult);
XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
schema.setElement(((Document)domResult.getNode()).getDocumen tElement());
xsdResource.getContents().add(schema);

// remove the schema from the original document and load the remainder
into the test resource.
document.getDocumentElement().removeChild(schemaElement);
transformer.transform(new DOMSource(document),new StreamResult(baos));
testResource.load(new
ByteArrayInputStream(baos.toByteArray()),resourceSet.getLoad Options());

"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cudtig$22c$1@www.eclipse.org">news:cudtig$22c$1@www.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">John,

This is much easier said than done. A schema model instance must be
constructed from a DOM, so you need to create a DOM when parsing and
then use that to create the XSDSchema. Similarly, when serializing, you
need to get the DOM from the XSDSchema and serialize that. The folks
doing a WSDL model need to solve this problem, but that's been done by
making the WSDL model work much like the XSD model. Probably is you
look at how XSDResourceImpl implements doSave and doLoad, it will be
more clear how it works (and that you have a hard problem to solve.).


John Sipher wrote:

</pre>
<blockquote type="cite">
<pre wrap="">I want to wrap an XML schema inside an XML document that will be
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->represented
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">by an EMF model, and I'd like to have the schema part of the document
processed by XSD when I load the parent document into my model.

For example, assume I have a schema that looks like this:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xs:schema targetNamespace=<a class="moz-txt-link-rfc2396E" href="http://mydomain/test">"http://mydomain/test"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://mydomain/test">"http://mydomain/test"</a>
xmlns:xs=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
elementFormDefault="unqualified" attributeFormDefault="unqualified"&gt;
&lt;xs:complexType name="RootElement"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="properties" type="ConfigProperty" minOccurs="0"
maxOccurs="unbounded"/&gt;
&lt;xs:any namespace=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name="ConfigProperty"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="name" type="xs:string"/&gt;
&lt;xs:element name="value" type="xs:string"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;

If I use that schema to generate an EMF model, I think the generated
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->model
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ought to be able to process a document that looks like this:
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;test:RootElement xmlns:test=<a class="moz-txt-link-rfc2396E" href="http://mydomain/test">"http://mydomain/test"</a>&gt;
&lt;properties&gt;
&lt;name&gt;name1&lt;/name&gt;
&lt;value&gt;value1&lt;/value&gt;
&lt;/properties&gt;
&lt;xs:schema targetNamespace=<a class="moz-txt-link-rfc2396E" href="http://mydomain/test">"http://mydomain/test"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://mydomain/test">"http://mydomain/test"</a>
xmlns:xs=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
elementFormDefault="unqualified"
attributeFormDefault="unqualified"&gt;
&lt;xs:complexType name="RootElement"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="properties" type="ConfigProperty" minOccurs="0"
maxOccurs="unbounded"/&gt;
&lt;xs:any namespace=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name="ConfigProperty"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="name" type="xs:string"/&gt;
&lt;xs:element name="value" type="xs:string"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;
&lt;/test:RootElement&gt;

In other words, the &lt;xs:schema&gt; element ought to be legal content for the
&lt;xs:any&gt; element in my schema. However, when I try to load the document
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->it
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">complains about Feature 'schema' not found. (model/test.test, 10, -1).

The code that tries to load the document looks like this:

XSDPackageImpl.init();
TestPackageImpl.init();

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*",new
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">TestResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;

Any suggestions?

Thanks,
John Sipher




</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------060302030506000303070109--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How do I include an XML schema in an EMF model? [message #391065 is a reply to message #391050] Fri, 11 February 2005 16:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.sipher.ssaglobal.com

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C51029.6B40A770
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks Ed. Now another problem. =20

This works as long as the schema embedded in my model document is =
entirely self contained, but it breaks when the schema has <xs:import> =
elements. I assume the problem is that XSDResourceImpl() can't resolve =
relative schema locations when it's loading from a ByteArrayInputStream. =
Is there an easy way around that (maybe something I can set in the load =
options)?

Thanks,
John
"Ed Merks" <merks@ca.ibm.com> wrote in message =
news:cug6ae$lrb$1@www.eclipse.org...
John,

You should register "test" and "xsd", not "*.test" and "*.xsd". Note =
also that if the schema contains schemaLocation=3D"..." where the ... is =
a relative path, it's important that the URI of the containing resource =
be an absolute path so that relative location can be interpreted =
properly. In that case "*.xsd" would not be so good and you might want =
to take the name of the actual location of the bigger file (modelURL) =
and append .xsd to it to create your "fake" XSD URI.

I also made a comment line below about the add of the resource being =
unnecessary since the createResource will already have added it...

John Sipher wrote:=20
Ed,

Thanks for the quick response. For my purposes the solution is =
relatively
easy now that I know I'm not missing something easy in the original
approach. I did run across something that didn't work as I thought it
should from reading the XSD FAQ.

I think I should be able to do this to get empty resources that I can =
load.
// initalize packages
XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();
// set up resource registry

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test=
",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd"=
,ne
w XSDResourceFactoryImpl());
// get "empty" resources
ResourceSet resourceSet =3D new ResourceSetImpl();
TestResourceImpl testResource =3D
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
XSDResourceImpl xsdResource =3D
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));

In both cases resourceSet.createResource() returns null, and I'm not =
sure
why. I traced into it and it looks as if the resource factory registry
hasn't been initialized yet.

John

The "solution" to the original problem follows. Please let me know if
anyone sees problems with it (exception handling obviously needs to be
added).

String modelURL =3D args[0];
DocumentBuilderFactory factory =3D =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder =3D factory.newDocumentBuilder();
Document document =3D builder.parse(new FileInputStream(modelURL));

ByteArrayOutputStream baos =3D new ByteArrayOutputStream();
Transformer transformer =3D
TransformerFactory.newInstance().newTransformer();

XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test=
",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd"=
,ne
w XSDResourceFactoryImpl());
ResourceSet resourceSet =3D new ResourceSetImpl();
// TestResourceImpl testResource =3D
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
// XSDResourceImpl xsdResource =3D
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
TestResourceImpl testResource =3D new
TestResourceImpl(URI.createURI("*.test"));
XSDResourceImpl xsdResource =3D new
XSDResourceImpl(URI.createURI("*.xsd"));
resourceSet.getResources().add(testResource);
resourceSet.getResources().add(xsdResource);
The created resource is already added, so this is a no-op.

// get the embedded schema, load it into an XSDSchema instance, and =
add
it to the xsd resource
Element schemaElement =3D
(Element)document.getDocumentElement().getElementsByTagNameN S( "http://www=
..w3
..org/2001/XMLSchema","schema").item(0);
DOMResult domResult =3D new DOMResult(builder.newDocument());
transformer.transform(new DOMSource(schemaElement),domResult);
XSDSchema schema =3D XSDFactory.eINSTANCE.createXSDSchema();
=
schema.setElement(((Document)domResult.getNode()).getDocumen tElement());
xsdResource.getContents().add(schema);

// remove the schema from the original document and load the =
remainder
into the test resource.
document.getDocumentElement().removeChild(schemaElement);
transformer.transform(new DOMSource(document),new =
StreamResult(baos));
testResource.load(new
ByteArrayInputStream(baos.toByteArray()),resourceSet.getLoad Options());

"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cudtig$22c$1@www.eclipse.org...
John,

This is much easier said than done. A schema model instance must be
constructed from a DOM, so you need to create a DOM when parsing and
then use that to create the XSDSchema. Similarly, when serializing, you
need to get the DOM from the XSDSchema and serialize that. The folks
doing a WSDL model need to solve this problem, but that's been done by
making the WSDL model work much like the XSD model. Probably is you
look at how XSDResourceImpl implements doSave and doLoad, it will be
more clear how it works (and that you have a hard problem to solve.).


John Sipher wrote:

I want to wrap an XML schema inside an XML document that will be
represented
by an EMF model, and I'd like to have the schema part of the document
processed by XSD when I load the parent document into my model.

For example, assume I have a schema that looks like this:

<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<xs:schema targetNamespace=3D"http://mydomain/test"
xmlns=3D"http://mydomain/test"
xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
elementFormDefault=3D"unqualified" attributeFormDefault=3D"unqualified">
<xs:complexType name=3D"RootElement">
<xs:sequence>
<xs:element name=3D"properties" type=3D"ConfigProperty" =
minOccurs=3D"0"
maxOccurs=3D"unbounded"/>
<xs:any namespace=3D"http://www.w3.org/2001/XMLSchema"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name=3D"ConfigProperty">
<xs:sequence>
<xs:element name=3D"name" type=3D"xs:string"/>
<xs:element name=3D"value" type=3D"xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

If I use that schema to generate an EMF model, I think the generated
model
ought to be able to process a document that looks like this:
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<test:RootElement xmlns:test=3D"http://mydomain/test">
<properties>
<name>name1</name>
<value>value1</value>
</properties>
<xs:schema targetNamespace=3D"http://mydomain/test"
xmlns=3D"http://mydomain/test"
xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
elementFormDefault=3D"unqualified"
attributeFormDefault=3D"unqualified">
<xs:complexType name=3D"RootElement">
<xs:sequence>
<xs:element name=3D"properties" type=3D"ConfigProperty" =
minOccurs=3D"0"
maxOccurs=3D"unbounded"/>
<xs:any namespace=3D"http://www.w3.org/2001/XMLSchema"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name=3D"ConfigProperty">
<xs:sequence>
<xs:element name=3D"name" type=3D"xs:string"/>
<xs:element name=3D"value" type=3D"xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</test:RootElement>

In other words, the <xs:schema> element ought to be legal content for =
the
<xs:any> element in my schema. However, when I try to load the document
it
complains about Feature 'schema' not found. (model/test.test, 10, -1).

The code that tries to load the document looks like this:

XSDPackageImpl.init();
TestPackageImpl.init();

=
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*",new=

TestResourceFactoryImpl());
ResourceSet resourceSet =3D new ResourceSetImpl();
resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;

Any suggestions?

Thanks,
John Sipher




=20

=20

------=_NextPart_000_0009_01C51029.6B40A770
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type =
content=3Dtext/html;charset=3DISO-8859-1>
<META content=3D"MSHTML 6.00.2800.1491" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Thanks Ed.&nbsp; Now another =
problem.&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This works as long as the schema =
embedded in my=20
model document is entirely self contained, but it breaks when the schema =
has=20
&lt;xs:import&gt; elements.&nbsp; I assume the problem is that =
XSDResourceImpl()=20
can't resolve relative schema locations when it's loading from a=20
ByteArrayInputStream.&nbsp; Is there an easy way around that (maybe =
something I=20
can set in the load options)?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>John</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ed Merks" &lt;<A =
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>&gt;=20
wrote in message <A=20
=
href=3D"news:cug6ae$lrb$1@www.eclipse.org">news:cug6ae$lrb$1@www.eclipse.=
org</A>...</DIV>John,<BR><PRE wrap=3D"">You should register "test" and =
"xsd", not "*.test" and "*.xsd". Note also that if the schema contains =
schemaLocation=3D"..." where the ... is a relative path, it's important =
that the URI of the containing resource be an absolute path so that =
relative location can be interpreted properly. In that case "*.xsd" =
would not be so good and you might want to take the name of the actual =
location of the bigger file (modelURL) and append .xsd to it to create =
your "fake" XSD URI.

I also made a comment line below about the add of the resource being =
unnecessary since the createResource will already have added it...
</PRE><BR>John Sipher wrote:=20
<BLOCKQUOTE cite=3Dmidcug16k$snl$1@www.eclipse.org type=3D"cite"><PRE =
wrap=3D"">Ed,

Thanks for the quick response. For my purposes the solution is =
relatively
easy now that I know I'm not missing something easy in the original
approach. I did run across something that didn't work as I thought it
should from reading the XSD FAQ.

I think I should be able to do this to get empty resources that I can =
load.
// initalize packages
XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();
// set up resource registry

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test=
",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd"=
,ne
w XSDResourceFactoryImpl());
// get "empty" resources
ResourceSet resourceSet =3D new ResourceSetImpl();
TestResourceImpl testResource =3D
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
XSDResourceImpl xsdResource =3D
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));

In both cases resourceSet.createResource() returns null, and I'm not =
sure
why. I traced into it and it looks as if the resource factory registry
hasn't been initialized yet.

John

The "solution" to the original problem follows. Please let me know if
anyone sees problems with it (exception handling obviously needs to be
added).

String modelURL =3D args[0];
DocumentBuilderFactory factory =3D =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder =3D factory.newDocumentBuilder();
Document document =3D builder.parse(new FileInputStream(modelURL));

ByteArrayOutputStream baos =3D new ByteArrayOutputStream();
Transformer transformer =3D
TransformerFactory.newInstance().newTransformer();

XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test=
",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd"=
,ne
w XSDResourceFactoryImpl());
ResourceSet resourceSet =3D new ResourceSetImpl();
// TestResourceImpl testResource =3D
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
// XSDResourceImpl xsdResource =3D
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
TestResourceImpl testResource =3D new
TestResourceImpl(URI.createURI("*.test"));
XSDResourceImpl xsdResource =3D new
XSDResourceImpl(URI.createURI("*.xsd"));
resourceSet.getResources().add(testResource);
resourceSet.getResources().add(xsdResource);
</PRE></BLOCKQUOTE>The created resource is already added, so this is a =

no-op.<BR>
<BLOCKQUOTE cite=3Dmidcug16k$snl$1@www.eclipse.org type=3D"cite"><PRE =
wrap=3D""> // get the embedded schema, load it into an XSDSchema =
instance, and add
it to the xsd resource
Element schemaElement =3D
(Element)document.getDocumentElement().getElementsByTagNameN S( <A =
class=3Dmoz-txt-link-rfc2396E =
href=3D"http://www.w3.org/2001/XMLSchema">"http://www.w3
..org/2001/XMLSchema"</A>,"schema").item(0);
DOMResult domResult =3D new DOMResult(builder.newDocument());
transformer.transform(new DOMSource(schemaElement),domResult);
XSDSchema schema =3D XSDFactory.eINSTANCE.createXSDSchema();
=
schema.setElement(((Document)domResult.getNode()).getDocumen tElement());
xsdResource.getContents().add(schema);

// remove the schema from the original document and load the =
remainder
into the test resource.
document.getDocumentElement().removeChild(schemaElement);
transformer.transform(new DOMSource(document),new =
StreamResult(baos));
testResource.load(new
ByteArrayInputStream(baos.toByteArray()),resourceSet.getLoad Options());

"Ed Merks" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</A> wrote in =
message
<A class=3Dmoz-txt-link-freetext =
href=3D"news:cudtig$22c$1@www.eclipse.org">news:cudtig$22c$1@www.eclipse.=
org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">John,

This is much easier said than done. A schema model instance must be
constructed from a DOM, so you need to create a DOM when parsing and
then use that to create the XSDSchema. Similarly, when serializing, you
need to get the DOM from the XSDSchema and serialize that. The folks
doing a WSDL model need to solve this problem, but that's been done by
making the WSDL model work much like the XSD model. Probably is you
look at how XSDResourceImpl implements doSave and doLoad, it will be
more clear how it works (and that you have a hard problem to solve.).


John Sipher wrote:

</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">I want to wrap an XML =
schema inside an XML document that will be
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->represented
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">by an EMF model, and I'd =
like to have the schema part of the document
processed by XSD when I load the parent document into my model.

For example, assume I have a schema that looks like this:

&lt;?xml version=3D"1.0" encoding=3D"UTF-8"?&gt;
&lt;xs:schema targetNamespace=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://mydomain/test">"http://mydomain/test"</A>
xmlns=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://mydomain/test">"http://mydomain/test"</A>
xmlns:xs=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSche=
ma"</A>
elementFormDefault=3D"unqualified" =
attributeFormDefault=3D"unqualified"&gt;
&lt;xs:complexType name=3D"RootElement"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=3D"properties" type=3D"ConfigProperty" =
minOccurs=3D"0"
maxOccurs=3D"unbounded"/&gt;
&lt;xs:any namespace=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSche=
ma"</A>/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name=3D"ConfigProperty"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=3D"name" type=3D"xs:string"/&gt;
&lt;xs:element name=3D"value" type=3D"xs:string"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;

If I use that schema to generate an EMF model, I think the generated
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->model
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">ought to be able to =
process a document that looks like this:
&lt;?xml version=3D"1.0" encoding=3D"UTF-8"?&gt;
&lt;test:RootElement xmlns:test=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://mydomain/test">"http://mydomain/test"</A>&gt;
&lt;properties&gt;
&lt;name&gt;name1&lt;/name&gt;
&lt;value&gt;value1&lt;/value&gt;
&lt;/properties&gt;
&lt;xs:schema targetNamespace=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://mydomain/test">"http://mydomain/test"</A>
xmlns=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://mydomain/test">"http://mydomain/test"</A>
xmlns:xs=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSche=
ma"</A>
elementFormDefault=3D"unqualified"
attributeFormDefault=3D"unqualified"&gt;
&lt;xs:complexType name=3D"RootElement"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=3D"properties" type=3D"ConfigProperty" =
minOccurs=3D"0"
maxOccurs=3D"unbounded"/&gt;
&lt;xs:any namespace=3D<A class=3Dmoz-txt-link-rfc2396E =
href=3D"http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSche=
ma"</A>/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name=3D"ConfigProperty"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=3D"name" type=3D"xs:string"/&gt;
&lt;xs:element name=3D"value" type=3D"xs:string"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;
&lt;/test:RootElement&gt;

In other words, the &lt;xs:schema&gt; element ought to be legal content =
for the
&lt;xs:any&gt; element in my schema. However, when I try to load the =
document
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->it
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">complains about Feature =
'schema' not found. (model/test.test, 10, -1).

The code that tries to load the document looks like this:

XSDPackageImpl.init();
TestPackageImpl.init();

</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->Resource.Factory.Registry.INSTANCE.getExtensionToFactory=
Map().put("*",new
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE =
wrap=3D"">TestResourceFactoryImpl());
ResourceSet resourceSet =3D new ResourceSetImpl();
resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;

Any suggestions?

Thanks,
John Sipher




</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->

</PRE></BLOCKQUOTE><BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0009_01C51029.6B40A770--
Re: How do I include an XML schema in an EMF model? [message #391071 is a reply to message #391065] Fri, 11 February 2005 16:35 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010501030403060100060501
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

John,

I was anticipating this problem which is why I added my comment about
making sure that the URI of the XSDResourceImpl is the correct absolute
URI against which relative locations should be resolved. Are you using
modelURL + ".xsd" as the URI now? The URI needs to be absolute, i.e,.
http://..., file:/, platform:/, and so on...


John Sipher wrote:

> Thanks Ed. Now another problem.
>
> This works as long as the schema embedded in my model document is
> entirely self contained, but it breaks when the schema has <xs:import>
> elements. I assume the problem is that XSDResourceImpl() can't
> resolve relative schema locations when it's loading from a
> ByteArrayInputStream. Is there an easy way around that (maybe
> something I can set in the load options)?
>
> Thanks,
> John
>
> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> wrote in
> message news:cug6ae$lrb$1@www.eclipse.org...
> John,
>
>You should register "test" and "xsd", not "*.test" and "*.xsd". Note also that if the schema contains schemaLocation="..." where the ... is a relative path, it's important that the URI of the containing resource be an absolute path so that relative location can be interpreted properly. In that case "*.xsd" would not be so good and you might want to take the name of the actual location of the bigger file (modelURL) and append .xsd to it to create your "fake" XSD URI.
>
>I also made a comment line below about the add of the resource being unnecessary since the createResource will already have added it...
>
>
>
> John Sipher wrote:
>
>>Ed,
>>
>>Thanks for the quick response. For my purposes the solution is relatively
>>easy now that I know I'm not missing something easy in the original
>>approach. I did run across something that didn't work as I thought it
>>should from reading the XSD FAQ.
>>
>>I think I should be able to do this to get empty resources that I can load.
>> // initalize packages
>> XSDPackage.eINSTANCE.getEFactoryInstance();
>> TestPackage.eINSTANCE.getEFactoryInstance();
>> // set up resource registry
>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
>>ew TestResourceFactoryImpl());
>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
>>w XSDResourceFactoryImpl());
>> // get "empty" resources
>> ResourceSet resourceSet = new ResourceSetImpl();
>> TestResourceImpl testResource =
>>(TestResourceImpl)resourceSet.createResource(URI.createURI( "*.test"));
>> XSDResourceImpl xsdResource =
>>(XSDResourceImpl)resourceSet.createResource(URI.createURI( "*.xsd"));
>>
>>In both cases resourceSet.createResource() returns null, and I'm not sure
>>why. I traced into it and it looks as if the resource factory registry
>>hasn't been initialized yet.
>>
>>John
>>
>>The "solution" to the original problem follows. Please let me know if
>>anyone sees problems with it (exception handling obviously needs to be
>>added).
>>
>> String modelURL = args[0];
>> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>> factory.setNamespaceAware(true);
>> DocumentBuilder builder = factory.newDocumentBuilder();
>> Document document = builder.parse(new FileInputStream(modelURL));
>>
>> ByteArrayOutputStream baos = new ByteArrayOutputStream();
>> Transformer transformer =
>>TransformerFactory.newInstance().newTransformer();
>>
>> XSDPackage.eINSTANCE.getEFactoryInstance();
>> TestPackage.eINSTANCE.getEFactoryInstance();
>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
>>ew TestResourceFactoryImpl());
>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
>>w XSDResourceFactoryImpl());
>> ResourceSet resourceSet = new ResourceSetImpl();
>>// TestResourceImpl testResource =
>>(TestResourceImpl)resourceSet.createResource(URI.createURI( "*.test"));
>>// XSDResourceImpl xsdResource =
>>(XSDResourceImpl)resourceSet.createResource(URI.createURI( "*.xsd"));
>> TestResourceImpl testResource = new
>>TestResourceImpl(URI.createURI("*.test"));
>> XSDResourceImpl xsdResource = new
>>XSDResourceImpl(URI.createURI("*.xsd"));
>> resourceSet.getResources().add(testResource);
>> resourceSet.getResources().add(xsdResource);
>>
>>
> The created resource is already added, so this is a no-op.
>
>> // get the embedded schema, load it into an XSDSchema instance, and add
>>it to the xsd resource
>> Element schemaElement =
>> (Element)document.getDocumentElement().getElementsByTagNameN S( "http://www.w3
>>.org/2001/XMLSchema","schema").item(0);
>> DOMResult domResult = new DOMResult(builder.newDocument());
>> transformer.transform(new DOMSource(schemaElement),domResult);
>> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
>> schema.setElement(((Document)domResult.getNode()).getDocumen tElement());
>> xsdResource.getContents().add(schema);
>>
>> // remove the schema from the original document and load the remainder
>>into the test resource.
>> document.getDocumentElement().removeChild(schemaElement);
>> transformer.transform(new DOMSource(document),new StreamResult(baos));
>> testResource.load(new
>> ByteArrayInputStream(baos.toByteArray()),resourceSet.getLoad Options());
>>
>>"Ed Merks" <merks@ca.ibm.com> wrote in message
>>news:cudtig$22c$1@www.eclipse.org...
>>
>>
>>>John,
>>>
>>>This is much easier said than done. A schema model instance must be
>>>constructed from a DOM, so you need to create a DOM when parsing and
>>>then use that to create the XSDSchema. Similarly, when serializing, you
>>>need to get the DOM from the XSDSchema and serialize that. The folks
>>>doing a WSDL model need to solve this problem, but that's been done by
>>>making the WSDL model work much like the XSD model. Probably is you
>>>look at how XSDResourceImpl implements doSave and doLoad, it will be
>>>more clear how it works (and that you have a hard problem to solve.).
>>>
>>>
>>>John Sipher wrote:
>>>
>>>
>>>
>>>>I want to wrap an XML schema inside an XML document that will be
>>>>
>>>>
>>represented
>>
>>
>>>>by an EMF model, and I'd like to have the schema part of the document
>>>>processed by XSD when I load the parent document into my model.
>>>>
>>>>For example, assume I have a schema that looks like this:
>>>>
>>>><?xml version="1.0" encoding="UTF-8"?>
>>>><xs:schema targetNamespace="http://mydomain/test"
>>>>xmlns="http://mydomain/test"
>>>>xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>>>elementFormDefault="unqualified" attributeFormDefault="unqualified">
>>>><xs:complexType name="RootElement">
>>>> <xs:sequence>
>>>> <xs:element name="properties" type="ConfigProperty" minOccurs="0"
>>>>maxOccurs="unbounded"/>
>>>> <xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
>>>> </xs:sequence>
>>>></xs:complexType>
>>>><xs:complexType name="ConfigProperty">
>>>> <xs:sequence>
>>>> <xs:element name="name" type="xs:string"/>
>>>> <xs:element name="value" type="xs:string"/>
>>>> </xs:sequence>
>>>></xs:complexType>
>>>></xs:schema>
>>>>
>>>>If I use that schema to generate an EMF model, I think the generated
>>>>
>>>>
>>model
>>
>>
>>>>ought to be able to process a document that looks like this:
>>>><?xml version="1.0" encoding="UTF-8"?>
>>>><test:RootElement xmlns:test="http://mydomain/test">
>>>> <properties>
>>>> <name>name1</name>
>>>> <value>value1</value>
>>>> </properties>
>>>> <xs:schema targetNamespace="http://mydomain/test"
>>>> xmlns="http://mydomain/test"
>>>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>>> elementFormDefault="unqualified"
>>>>attributeFormDefault="unqualified">
>>>> <xs:complexType name="RootElement">
>>>> <xs:sequence>
>>>> <xs:element name="properties" type="ConfigProperty" minOccurs="0"
>>>>maxOccurs="unbounded"/>
>>>> <xs:any namespace="http://www.w3.org/2001/XMLSchema"/>
>>>> </xs:sequence>
>>>> </xs:complexType>
>>>> <xs:complexType name="ConfigProperty">
>>>> <xs:sequence>
>>>> <xs:element name="name" type="xs:string"/>
>>>> <xs:element name="value" type="xs:string"/>
>>>> </xs:sequence>
>>>> </xs:complexType>
>>>> </xs:schema>
>>>></test:RootElement>
>>>>
>>>>In other words, the <xs:schema> element ought to be legal content for the
>>>><xs:any> element in my schema. However, when I try to load the document
>>>>
>>>>
>>it
>>
>>
>>>>complains about Feature 'schema' not found. (model/test.test, 10, -1).
>>>>
>>>>The code that tries to load the document looks like this:
>>>>
>>>> XSDPackageImpl.init();
>>>> TestPackageImpl.init();
>>>>
>>>>
>>>>
>> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*",new
>>
>>
>>>>TestResourceFactoryImpl());
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>> resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;
>>>>
>>>>Any suggestions?
>>>>
>>>>Thanks,
>>>>John Sipher
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>>
>


--------------010501030403060100060501
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
John,<br>
<br>
I was anticipating this problem which is why I added my comment about
making sure that the URI of the XSDResourceImpl is the correct absolute
URI against which relative locations should be resolved.&nbsp; Are you using
modelURL&nbsp; + ".xsd" as the URI now?&nbsp; The URI needs to be absolute, i.e,.
<a class="moz-txt-link-freetext" href="http://">http://</a>..., <a class="moz-txt-link-freetext" href="file:/">file:/</a>, platform:/, and so on...<br>
<br>
<br>
John Sipher wrote:
<blockquote cite="midcuil1r$2rd$1@www.eclipse.org" type="cite">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta content="MSHTML 6.00.2800.1491" name="GENERATOR">
<style></style>
<div><font face="Arial" size="2">Thanks Ed.&nbsp; Now another problem.&nbsp; </font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">This works as long as the schema
embedded in my model document is entirely self contained, but it breaks
when the schema has &lt;xs:import&gt; elements.&nbsp; I assume the problem
is that XSDResourceImpl() can't resolve relative schema locations when
it's loading from a ByteArrayInputStream.&nbsp; Is there an easy way around
that (maybe something I can set in the load options)?</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Thanks,</font></div>
<div><font face="Arial" size="2">John</font></div>
<blockquote
style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div>"Ed Merks" &lt;<a href="mailto:merks@ca.ibm.com">merks@ca.ibm.com</a>&gt;
wrote in message <a href="news:cug6ae$lrb$1@www.eclipse.org">news:cug6ae$lrb$1@www.eclipse.org</a>...</div>
John,<br>
<pre wrap="">You should register "test" and "xsd", not "*.test" and "*.xsd". Note also that if the schema contains schemaLocation="..." where the ... is a relative path, it's important that the URI of the containing resource be an absolute path so that relative location can be interpreted properly. In that case "*.xsd" would not be so good and you might want to take the name of the actual location of the bigger file (modelURL) and append .xsd to it to create your "fake" XSD URI.

I also made a comment line below about the add of the resource being unnecessary since the createResource will already have added it...
</pre>
<br>
John Sipher wrote:
<blockquote cite="midcug16k$snl$1@www.eclipse.org" type="cite">
<pre wrap="">Ed,

Thanks for the quick response. For my purposes the solution is relatively
easy now that I know I'm not missing something easy in the original
approach. I did run across something that didn't work as I thought it
should from reading the XSD FAQ.

I think I should be able to do this to get empty resources that I can load.
// initalize packages
XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();
// set up resource registry

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
w XSDResourceFactoryImpl());
// get "empty" resources
ResourceSet resourceSet = new ResourceSetImpl();
TestResourceImpl testResource =
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
XSDResourceImpl xsdResource =
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));

In both cases resourceSet.createResource() returns null, and I'm not sure
why. I traced into it and it looks as if the resource factory registry
hasn't been initialized yet.

John

The "solution" to the original problem follows. Please let me know if
anyone sees problems with it (exception handling obviously needs to be
added).

String modelURL = args[0];
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new FileInputStream(modelURL));

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Transformer transformer =
TransformerFactory.newInstance().newTransformer();

XSDPackage.eINSTANCE.getEFactoryInstance();
TestPackage.eINSTANCE.getEFactoryInstance();

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.test",n
ew TestResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*.xsd",ne
w XSDResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
// TestResourceImpl testResource =
(TestResourceImpl)resourceSet.createResource(URI.createURI("*.test "));
// XSDResourceImpl xsdResource =
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd "));
TestResourceImpl testResource = new
TestResourceImpl(URI.createURI("*.test"));
XSDResourceImpl xsdResource = new
XSDResourceImpl(URI.createURI("*.xsd"));
resourceSet.getResources().add(testResource);
resourceSet.getResources().add(xsdResource);
</pre>
</blockquote>
The created resource is already added, so this is a no-op.<br>
<blockquote cite="midcug16k$snl$1@www.eclipse.org" type="cite">
<pre wrap=""> // get the embedded schema, load it into an XSDSchema instance, and add
it to the xsd resource
Element schemaElement =
(Element)document.getDocumentElement().getElementsByTagNameN S( <a
class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3
..org/2001/XMLSchema"</a>,"schema").item(0);
DOMResult domResult = new DOMResult(builder.newDocument());
transformer.transform(new DOMSource(schemaElement),domResult);
XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
schema.setElement(((Document)domResult.getNode()).getDocumen tElement());
xsdResource.getContents().add(schema);

// remove the schema from the original document and load the remainder
into the test resource.
document.getDocumentElement().removeChild(schemaElement);
transformer.transform(new DOMSource(document),new StreamResult(baos));
testResource.load(new
ByteArrayInputStream(baos.toByteArray()),resourceSet.getLoad Options());

"Ed Merks" <a class="moz-txt-link-rfc2396E"
href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext"
href="news:cudtig$22c$1@www.eclipse.org">news:cudtig$22c$1@www.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">John,

This is much easier said than done. A schema model instance must be
constructed from a DOM, so you need to create a DOM when parsing and
then use that to create the XSDSchema. Similarly, when serializing, you
need to get the DOM from the XSDSchema and serialize that. The folks
doing a WSDL model need to solve this problem, but that's been done by
making the WSDL model work much like the XSD model. Probably is you
look at how XSDResourceImpl implements doSave and doLoad, it will be
more clear how it works (and that you have a hard problem to solve.).


John Sipher wrote:

</pre>
<blockquote type="cite">
<pre wrap="">I want to wrap an XML schema inside an XML document that will be
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->represented
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">by an EMF model, and I'd like to have the schema part of the document
processed by XSD when I load the parent document into my model.

For example, assume I have a schema that looks like this:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xs:schema targetNamespace=<a class="moz-txt-link-rfc2396E"
href="http://mydomain/test">"http://mydomain/test"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://mydomain/test">"http://mydomain/test"</a>
xmlns:xs=<a class="moz-txt-link-rfc2396E"
href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
elementFormDefault="unqualified" attributeFormDefault="unqualified"&gt;
&lt;xs:complexType name="RootElement"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="properties" type="ConfigProperty" minOccurs="0"
maxOccurs="unbounded"/&gt;
&lt;xs:any namespace=<a class="moz-txt-link-rfc2396E"
href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name="ConfigProperty"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="name" type="xs:string"/&gt;
&lt;xs:element name="value" type="xs:string"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;

If I use that schema to generate an EMF model, I think the generated
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->model
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ought to be able to process a document that looks like this:
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;test:RootElement xmlns:test=<a class="moz-txt-link-rfc2396E"
href="http://mydomain/test">"http://mydomain/test"</a>&gt;
&lt;properties&gt;
&lt;name&gt;name1&lt;/name&gt;
&lt;value&gt;value1&lt;/value&gt;
&lt;/properties&gt;
&lt;xs:schema targetNamespace=<a class="moz-txt-link-rfc2396E"
href="http://mydomain/test">"http://mydomain/test"</a>
xmlns=<a class="moz-txt-link-rfc2396E"
href="http://mydomain/test">"http://mydomain/test"</a>
xmlns:xs=<a class="moz-txt-link-rfc2396E"
href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
elementFormDefault="unqualified"
attributeFormDefault="unqualified"&gt;
&lt;xs:complexType name="RootElement"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="properties" type="ConfigProperty" minOccurs="0"
maxOccurs="unbounded"/&gt;
&lt;xs:any namespace=<a class="moz-txt-link-rfc2396E"
href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:complexType name="ConfigProperty"&gt;
&lt;xs:sequence&gt;
&lt;xs:element name="name" type="xs:string"/&gt;
&lt;xs:element name="value" type="xs:string"/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:schema&gt;
&lt;/test:RootElement&gt;

In other words, the &lt;xs:schema&gt; element ought to be legal content for the
&lt;xs:any&gt; element in my schema. However, when I try to load the document
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->it
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">complains about Feature 'schema' not found. (model/test.test, 10, -1).

The code that tries to load the document looks like this:

XSDPackageImpl.init();
TestPackageImpl.init();

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "*",new
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">TestResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResource(URI.createDeviceURI(schemaURL),true) ;

Any suggestions?

Thanks,
John Sipher




</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------010501030403060100060501--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Dynamic model transformation
Next Topic:Code generation pbm: missing class
Goto Forum:
  


Current Time: Tue Apr 23 17:07:39 GMT 2024

Powered by FUDForum. Page generated in 0.04051 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top