Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Handling embedded XML schema
Handling embedded XML schema [message #424208] Mon, 20 October 2008 17:59 Go to next message
Jay Lawrence is currently offline Jay LawrenceFriend
Messages: 7
Registered: July 2009
Junior Member
I'm working with an XML schema (beyond my control) that allows "extension"
elements so that users of the schema have a place to put arbitrary embedded
XML content.

The schema below is a representative sample. It contains a Root object, that
can have an unbounded number of Entry elements, each of which has a Name and
an Extension opportunity.

An example of the form of schema is:

------------ begin base.xsd -------------

<xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:base="http://example.eclipse.org/schema/base.xsd"
targetNamespace="http://example.eclipse.org/schema/base.xsd">

<xsd:complexType name="Extension">
<xsd:sequence>
<xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Entry">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="extension" type="base:Extension"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Root">
<xsd:sequence>
<xsd:element name="entry" maxOccurs="unbounded"
type="base:Entry"></xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="root" type="base:Root"></xsd:element>

</xsd:schema>

----------- end base.xsd ---------------

The key element here is the:

<xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/>

This is converted into a Feature Map in the generated model as documented in
the EMF book (I have the latest September version of the Rough Cut).

If I have a second schema that I want to place in this extension location
and read in as an EMF model how can this be accomplished?

I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
dynamic ecore model that I have to use reflection on to get at. I instead
want to use my own EMF model for the second embedded schema.

For completeness. Here is an example of a second schema:

------------- begin myext.xsd --------------

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
targetNamespace="http://example.eclipse.org/schema/myext.xsd">

<xsd:complexType name="Info">
<xsd:sequence>
<xsd:element name="content" type="xsd:string"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="info" type="myext:Info"/>

</xsd:schema>

------------- end myext.xsd --------------------

And a document that uses the base schema and the extension schema as an
embedded element

----------- begin useextensioninbase.xml ---------------------

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
xmlns="http://example.eclipse.org/schema/base.xsd"
xsi:schemaLocation="http://example.eclipse.org/schema/base.xsd
base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd">
<entry xmlns="">
<name>entry1</name>
<extension><myext:info>
<content xmlns="">"This string is content"</content>
</myext:info></extension>
</entry>
</root>

----------- end useextensioninbase.xml -------------------

Is there a way (when I arrive at the <extension> entry) to tell EMF that the
contents should be serialized as another embedded EMF model?

Thanks,

Jay
Re: Handling embedded XML schema [message #424212 is a reply to message #424208] Mon, 20 October 2008 18:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050209060307020407020706
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jay,

Comments below.


Jay Lawrence wrote:
> I'm working with an XML schema (beyond my control) that allows "extension"
> elements so that users of the schema have a place to put arbitrary embedded
> XML content.
>
> The schema below is a representative sample. It contains a Root object, that
> can have an unbounded number of Entry elements, each of which has a Name and
> an Extension opportunity.
>
> An example of the form of schema is:
>
> ------------ begin base.xsd -------------
>
> <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema
> xmlns:base="http://example.eclipse.org/schema/base.xsd"
> targetNamespace="http://example.eclipse.org/schema/base.xsd">
>
> <xsd:complexType name="Extension">
> <xsd:sequence>
> <xsd:any namespace="##any" processContents="lax"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="Entry">
> <xsd:sequence>
> <xsd:element name="name" type="xsd:string"/>
> <xsd:element name="extension" type="base:Extension"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="Root">
> <xsd:sequence>
> <xsd:element name="entry" maxOccurs="unbounded"
> type="base:Entry"></xsd:element>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:element name="root" type="base:Root"></xsd:element>
>
> </xsd:schema>
>
> ----------- end base.xsd ---------------
>
> The key element here is the:
>
> <xsd:any namespace="##any" processContents="lax"
> maxOccurs="unbounded"/>
>
> This is converted into a Feature Map in the generated model as documented in
> the EMF book (I have the latest September version of the Rough Cut).
>
It should be in print in December. Woo hoo!
> If I have a second schema that I want to place in this extension location
> and read in as an EMF model how can this be accomplished?
>
Generally you'd do:

extension.getAny().add(XyzPacakge.Literals.DOCUMENT_ROOT__<element >,
<value-of-element's-type>).

Or this would accomplish the same:

extension.getAny().list(XyzPacakge.Literals.DOCUMENT_ROOT__<element >).add(<value-of-element's-type>).

> I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
> dynamic ecore model that I have to use reflection on to get at. I instead
> want to use my own EMF model for the second embedded schema.
>
> For completeness. Here is an example of a second schema:
>
> ------------- begin myext.xsd --------------
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
> targetNamespace="http://example.eclipse.org/schema/myext.xsd">
>
> <xsd:complexType name="Info">
> <xsd:sequence>
> <xsd:element name="content" type="xsd:string"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:element name="info" type="myext:Info"/>
>
> </xsd:schema>
>
> ------------- end myext.xsd --------------------
>
Substitute INFO above and create an instance of Info for the value.
> And a document that uses the base schema and the extension schema as an
> embedded element
>
> ----------- begin useextensioninbase.xml ---------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
> xmlns="http://example.eclipse.org/schema/base.xsd"
> xsi:schemaLocation="http://example.eclipse.org/schema/base.xsd
> base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd">
> <entry xmlns="">
> <name>entry1</name>
> <extension><myext:info>
> <content xmlns="">"This string is content"</content>
> </myext:info></extension>
> </entry>
> </root>
>
> ----------- end useextensioninbase.xml -------------------
>
> Is there a way (when I arrive at the <extension> entry) to tell EMF that the
> contents should be serialized as another embedded EMF model?
>
Yep. Just get used to working with the features of the document root
class of the other models...
> Thanks,
>
> Jay
>
>
>

--------------050209060307020407020706
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">
Jay,<br>
<br>
Comments below.<br>
<br>
<br>
Jay Lawrence wrote:
<blockquote cite="mid:gdiguh$v9q$1@build.eclipse.org" type="cite">
<pre wrap="">I'm working with an XML schema (beyond my control) that allows "extension"
elements so that users of the schema have a place to put arbitrary embedded
XML content.

The schema below is a representative sample. It contains a Root object, that
can have an unbounded number of Entry elements, each of which has a Name and
an Extension opportunity.

An example of the form of schema is:

------------ begin base.xsd -------------

&lt;xsd:schema xmlns:xsd=<a class="moz-txt-link-freetext" href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>
xmlns:base=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/base.xsd">"http://example.eclipse.org/schema/base.xsd"</a>
targetNamespace=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/base.xsd">"http://example.eclipse.org/schema/base.xsd"</a>&gt;

&lt;xsd:complexType name="Extension"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;

&lt;xsd:complexType name="Entry"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="name" type="xsd:string"/&gt;
&lt;xsd:element name="extension" type="base:Extension"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;

&lt;xsd:complexType name="Root"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="entry" maxOccurs="unbounded"
type="base:Entry"&gt;&lt;/xsd:element&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;

&lt;xsd:element name="root" type="base:Root"&gt;&lt;/xsd:element&gt;

&lt;/xsd:schema&gt;

----------- end base.xsd ---------------

The key element here is the:

&lt;xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/&gt;

This is converted into a Feature Map in the generated model as documented in
the EMF book (I have the latest September version of the Rough Cut).
</pre>
</blockquote>
It should be in print in December.&nbsp; Woo hoo!<br>
<blockquote cite="mid:gdiguh$v9q$1@build.eclipse.org" type="cite">
<pre wrap="">
If I have a second schema that I want to place in this extension location
and read in as an EMF model how can this be accomplished?
</pre>
</blockquote>
Generally you'd do:<br>
<blockquote> &nbsp;extension.getAny().add(XyzPacakge.Literals.DOCUMEN T_ROOT__&lt;element&gt;,
&lt;value-of-element's-type&gt;).<br>
</blockquote>
Or this would accomplish the same:<br>
<blockquote> extension.getAny().list(XyzPacakge.Literals.DOCUMENT_ROOT__& amp;lt;element&gt;).add(&lt;value-of-element's-type& amp;gt;). </blockquote>
<blockquote cite="mid:gdiguh$v9q$1@build.eclipse.org" type="cite">
<pre wrap="">
I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
dynamic ecore model that I have to use reflection on to get at. I instead
want to use my own EMF model for the second embedded schema.

For completeness. Here is an example of a second schema:

------------- begin myext.xsd --------------

&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
&lt;xsd:schema xmlns:xsd=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
xmlns:myext=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/myext.xsd">"http://example.eclipse.org/schema/myext.xsd"</a>
targetNamespace=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/myext.xsd">"http://example.eclipse.org/schema/myext.xsd"</a>&gt;

&lt;xsd:complexType name="Info"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="content" type="xsd:string"
maxOccurs="unbounded"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;

&lt;xsd:element name="info" type="myext:Info"/&gt;

&lt;/xsd:schema&gt;

------------- end myext.xsd --------------------
</pre>
</blockquote>
Substitute INFO above and create an instance of Info for the value.<br>
<blockquote cite="mid:gdiguh$v9q$1@build.eclipse.org" type="cite">
<pre wrap="">
And a document that uses the base schema and the extension schema as an
embedded element

----------- begin useextensioninbase.xml ---------------------

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;root xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns:myext=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/myext.xsd">"http://example.eclipse.org/schema/myext.xsd"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/base.xsd">"http://example.eclipse.org/schema/base.xsd"</a>
xsi:schemaLocation=<a class="moz-txt-link-rfc2396E" href=" http://example.eclipse.org/schema/base.xsdbase.xsdhttp://exa mple.eclipse.org/schema/myext.xsdmyext.xsd">"http://example.eclipse.org/schema/base.xsd
base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd"</a>&gt;
&lt;entry xmlns=""&gt;
&lt;name&gt;entry1&lt;/name&gt;
&lt;extension&gt;&lt;myext:info&gt;
&lt;content xmlns=""&gt;"This string is content"&lt;/content&gt;
&lt;/myext:info&gt;&lt;/extension&gt;
&lt;/entry&gt;
&lt;/root&gt;

----------- end useextensioninbase.xml -------------------

Is there a way (when I arrive at the &lt;extension&gt; entry) to tell EMF that the
contents should be serialized as another embedded EMF model?
</pre>
</blockquote>
Yep.&nbsp; Just get used to working with the features of the document root
class of the other models...<br>
<blockquote cite="mid:gdiguh$v9q$1@build.eclipse.org" type="cite">
<pre wrap="">
Thanks,

Jay


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

--------------050209060307020407020706--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Handling embedded XML schema [message #424213 is a reply to message #424212] Mon, 20 October 2008 20:04 Go to previous messageGo to next message
Jay Lawrence is currently offline Jay LawrenceFriend
Messages: 7
Registered: July 2009
Junior Member
Thanks Ed,

The interface to FeatureMaps baffles me ...

You're explanation makes sense for creating such a document. Can you help me
get the value back out?

I'm in a doSwitch for the Extension object and have code like:

public Object caseExtension (Extension object) {
System.out.println("Extension: " + object.toString());
Extension ext = object;
FeatureMap baseMap = ext.getAny();

// Now how do I get an Info Object? // The following gives me a Casting
exception
Info info = baseMap.get(MyextPackage.Literals.DOCUMENT_ROOT__INFO,
true);

System.out.println("INFO: " + info.toString());
return Boolean.FALSE;
}

Sincerely,

Jay



"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:gdik42$rcl$1@build.eclipse.org...
Jay,

Comments below.


Jay Lawrence wrote:
I'm working with an XML schema (beyond my control) that allows "extension"
elements so that users of the schema have a place to put arbitrary embedded
XML content.

The schema below is a representative sample. It contains a Root object, that
can have an unbounded number of Entry elements, each of which has a Name and
an Extension opportunity.

An example of the form of schema is:

------------ begin base.xsd -------------

<xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:base="http://example.eclipse.org/schema/base.xsd"
targetNamespace="http://example.eclipse.org/schema/base.xsd">

<xsd:complexType name="Extension">
<xsd:sequence>
<xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Entry">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="extension" type="base:Extension"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Root">
<xsd:sequence>
<xsd:element name="entry" maxOccurs="unbounded"
type="base:Entry"></xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="root" type="base:Root"></xsd:element>

</xsd:schema>

----------- end base.xsd ---------------

The key element here is the:

<xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/>

This is converted into a Feature Map in the generated model as documented in
the EMF book (I have the latest September version of the Rough Cut).

It should be in print in December. Woo hoo!

If I have a second schema that I want to place in this extension location
and read in as an EMF model how can this be accomplished?

Generally you'd do:

extension.getAny().add(XyzPacakge.Literals.DOCUMENT_ROOT__<element >,
<value-of-element's-type>).

Or this would accomplish the same:

extension.getAny().list(XyzPacakge.Literals.DOCUMENT_ROOT__<element >).add(<value-of-element's-type>).
I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
dynamic ecore model that I have to use reflection on to get at. I instead
want to use my own EMF model for the second embedded schema.

For completeness. Here is an example of a second schema:

------------- begin myext.xsd --------------

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
targetNamespace="http://example.eclipse.org/schema/myext.xsd">

<xsd:complexType name="Info">
<xsd:sequence>
<xsd:element name="content" type="xsd:string"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="info" type="myext:Info"/>

</xsd:schema>

------------- end myext.xsd --------------------

Substitute INFO above and create an instance of Info for the value.

And a document that uses the base schema and the extension schema as an
embedded element

----------- begin useextensioninbase.xml ---------------------

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
xmlns="http://example.eclipse.org/schema/base.xsd"
xsi:schemaLocation="http://example.eclipse.org/schema/base.xsd
base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd">
<entry xmlns="">
<name>entry1</name>
<extension><myext:info>
<content xmlns="">"This string is content"</content>
</myext:info></extension>
</entry>
</root>

----------- end useextensioninbase.xml -------------------

Is there a way (when I arrive at the <extension> entry) to tell EMF that the
contents should be serialized as another embedded EMF model?

Yep. Just get used to working with the features of the document root class
of the other models...

Thanks,

Jay
Re: Handling embedded XML schema [message #424215 is a reply to message #424213] Mon, 20 October 2008 20:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090005080300020500070400
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jay,

Comments below.

Jay Lawrence wrote:
> Thanks Ed,
>
> The interface to FeatureMaps baffles me ...
>
And I thought it was so intuitively obvious it didn't need Javadoc. :-P
> You're explanation makes sense for creating such a document. Can you help me
> get the value back out?
>
Jeesh, you want to get it out too? Hehehe.
> I'm in a doSwitch for the Extension object and have code like:
>
> public Object caseExtension (Extension object) {
> System.out.println("Extension: " + object.toString());
> Extension ext = object;
> FeatureMap baseMap = ext.getAny();
>
> // Now how do I get an Info Object? // The following gives me a Casting
> exception
> Info info = baseMap.get(MyextPackage.Literals.DOCUMENT_ROOT__INFO,
> true);
>
Because there can be a whole list of them, so you need to ask for the
whole list and then iterate over it:

baseMap.list(MyextPackage.Literals.DOCUMENT_ROOT__INFO)

If the wildcard couldn't repeat then what you has before would have been
correct. This is why we have FeatureMapUtil.isMany; whether the
document root feature is allowed to repeat or not is relative to the
multiplicity of the feature map that holds it...

It's all so complicated, but that's XML Schema for you...
> System.out.println("INFO: " + info.toString());
> return Boolean.FALSE;
> }
>
> Sincerely,
>
> Jay
>
>
>
> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
> news:gdik42$rcl$1@build.eclipse.org...
> Jay,
>
> Comments below.
>
>
> Jay Lawrence wrote:
> I'm working with an XML schema (beyond my control) that allows "extension"
> elements so that users of the schema have a place to put arbitrary embedded
> XML content.
>
> The schema below is a representative sample. It contains a Root object, that
> can have an unbounded number of Entry elements, each of which has a Name and
> an Extension opportunity.
>
> An example of the form of schema is:
>
> ------------ begin base.xsd -------------
>
> <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema
> xmlns:base="http://example.eclipse.org/schema/base.xsd"
> targetNamespace="http://example.eclipse.org/schema/base.xsd">
>
> <xsd:complexType name="Extension">
> <xsd:sequence>
> <xsd:any namespace="##any" processContents="lax"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="Entry">
> <xsd:sequence>
> <xsd:element name="name" type="xsd:string"/>
> <xsd:element name="extension" type="base:Extension"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="Root">
> <xsd:sequence>
> <xsd:element name="entry" maxOccurs="unbounded"
> type="base:Entry"></xsd:element>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:element name="root" type="base:Root"></xsd:element>
>
> </xsd:schema>
>
> ----------- end base.xsd ---------------
>
> The key element here is the:
>
> <xsd:any namespace="##any" processContents="lax"
> maxOccurs="unbounded"/>
>
> This is converted into a Feature Map in the generated model as documented in
> the EMF book (I have the latest September version of the Rough Cut).
>
> It should be in print in December. Woo hoo!
>
> If I have a second schema that I want to place in this extension location
> and read in as an EMF model how can this be accomplished?
>
> Generally you'd do:
>
> extension.getAny().add(XyzPacakge.Literals.DOCUMENT_ROOT__<element >,
> <value-of-element's-type>).
>
> Or this would accomplish the same:
>
> extension.getAny().list(XyzPacakge.Literals.DOCUMENT_ROOT__<element >).add(<value-of-element's-type>).
> I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
> dynamic ecore model that I have to use reflection on to get at. I instead
> want to use my own EMF model for the second embedded schema.
>
> For completeness. Here is an example of a second schema:
>
> ------------- begin myext.xsd --------------
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
> targetNamespace="http://example.eclipse.org/schema/myext.xsd">
>
> <xsd:complexType name="Info">
> <xsd:sequence>
> <xsd:element name="content" type="xsd:string"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:element name="info" type="myext:Info"/>
>
> </xsd:schema>
>
> ------------- end myext.xsd --------------------
>
> Substitute INFO above and create an instance of Info for the value.
>
> And a document that uses the base schema and the extension schema as an
> embedded element
>
> ----------- begin useextensioninbase.xml ---------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
> xmlns="http://example.eclipse.org/schema/base.xsd"
> xsi:schemaLocation="http://example.eclipse.org/schema/base.xsd
> base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd">
> <entry xmlns="">
> <name>entry1</name>
> <extension><myext:info>
> <content xmlns="">"This string is content"</content>
> </myext:info></extension>
> </entry>
> </root>
>
> ----------- end useextensioninbase.xml -------------------
>
> Is there a way (when I arrive at the <extension> entry) to tell EMF that the
> contents should be serialized as another embedded EMF model?
>
> Yep. Just get used to working with the features of the document root class
> of the other models...
>
> Thanks,
>
> Jay
>
>
>
>
>
>

--------------090005080300020500070400
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">
Jay,<br>
<br>
Comments below.<br>
<br>
Jay Lawrence wrote:
<blockquote cite="mid:gdio8t$fq1$1@build.eclipse.org" type="cite">
<pre wrap="">Thanks Ed,

The interface to FeatureMaps baffles me ...
</pre>
</blockquote>
And I thought it was so intuitively obvious it didn't need Javadoc. :-P<br>
<blockquote cite="mid:gdio8t$fq1$1@build.eclipse.org" type="cite">
<pre wrap="">
You're explanation makes sense for creating such a document. Can you help me
get the value back out?
</pre>
</blockquote>
Jeesh, you want to get it out too? Hehehe.<br>
<blockquote cite="mid:gdio8t$fq1$1@build.eclipse.org" type="cite">
<pre wrap="">
I'm in a doSwitch for the Extension object and have code like:

public Object caseExtension (Extension object) {
System.out.println("Extension: " + object.toString());
Extension ext = object;
FeatureMap baseMap = ext.getAny();

// Now how do I get an Info Object? // The following gives me a Casting
exception
Info info = baseMap.get(MyextPackage.Literals.DOCUMENT_ROOT__INFO,
true);
</pre>
</blockquote>
Because there can be a whole list of them, so you need to ask for the
whole list and then iterate over it:<br>
<blockquote>baseMap.list(MyextPackage.Literals.DOCUMENT_ROOT__INFO) <br>
</blockquote>
If the wildcard couldn't repeat then what you has before would have
been correct.&nbsp; This is why we have FeatureMapUtil.isMany; whether the
document root feature is allowed to repeat or not is relative to the
multiplicity of the feature map that holds it...<br>
<br>
It's all so complicated, but that's XML Schema for you...<br>
<blockquote cite="mid:gdio8t$fq1$1@build.eclipse.org" type="cite">
<pre wrap="">
System.out.println("INFO: " + info.toString());
return Boolean.FALSE;
}

Sincerely,

Jay



"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:Ed.Merks@gmail.com">&lt;Ed.Merks@gmail.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:gdik42$rcl$1@build.eclipse.org">news:gdik42$rcl$1@build.eclipse.org</a>...
Jay,

Comments below.


Jay Lawrence wrote:
I'm working with an XML schema (beyond my control) that allows "extension"
elements so that users of the schema have a place to put arbitrary embedded
XML content.

The schema below is a representative sample. It contains a Root object, that
can have an unbounded number of Entry elements, each of which has a Name and
an Extension opportunity.

An example of the form of schema is:

------------ begin base.xsd -------------

&lt;xsd:schema xmlns:xsd=<a class="moz-txt-link-freetext" href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>
xmlns:base=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/base.xsd">"http://example.eclipse.org/schema/base.xsd"</a>
targetNamespace=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/base.xsd">"http://example.eclipse.org/schema/base.xsd"</a>&gt;

&lt;xsd:complexType name="Extension"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;

&lt;xsd:complexType name="Entry"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="name" type="xsd:string"/&gt;
&lt;xsd:element name="extension" type="base:Extension"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;

&lt;xsd:complexType name="Root"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="entry" maxOccurs="unbounded"
type="base:Entry"&gt;&lt;/xsd:element&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;

&lt;xsd:element name="root" type="base:Root"&gt;&lt;/xsd:element&gt;

&lt;/xsd:schema&gt;

----------- end base.xsd ---------------

The key element here is the:

&lt;xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/&gt;

This is converted into a Feature Map in the generated model as documented in
the EMF book (I have the latest September version of the Rough Cut).

It should be in print in December. Woo hoo!

If I have a second schema that I want to place in this extension location
and read in as an EMF model how can this be accomplished?

Generally you'd do:

extension.getAny().add(XyzPacakge.Literals.DOCUMENT_ROOT__&a mp;lt;element&gt;,
&lt;value-of-element's-type&gt;).

Or this would accomplish the same:

extension.getAny().list(XyzPacakge.Literals.DOCUMENT_ROOT__& amp;lt;element&gt;).add(&lt;value-of-element's-type& amp;gt;).
I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
dynamic ecore model that I have to use reflection on to get at. I instead
want to use my own EMF model for the second embedded schema.

For completeness. Here is an example of a second schema:

------------- begin myext.xsd --------------

&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
&lt;xsd:schema xmlns:xsd=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
xmlns:myext=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/myext.xsd">"http://example.eclipse.org/schema/myext.xsd"</a>
targetNamespace=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/myext.xsd">"http://example.eclipse.org/schema/myext.xsd"</a>&gt;

&lt;xsd:complexType name="Info"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="content" type="xsd:string"
maxOccurs="unbounded"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;

&lt;xsd:element name="info" type="myext:Info"/&gt;

&lt;/xsd:schema&gt;

------------- end myext.xsd --------------------

Substitute INFO above and create an instance of Info for the value.

And a document that uses the base schema and the extension schema as an
embedded element

----------- begin useextensioninbase.xml ---------------------

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;root xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns:myext=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/myext.xsd">"http://example.eclipse.org/schema/myext.xsd"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://example.eclipse.org/schema/base.xsd">"http://example.eclipse.org/schema/base.xsd"</a>
xsi:schemaLocation=<a class="moz-txt-link-rfc2396E" href=" http://example.eclipse.org/schema/base.xsdbase.xsdhttp://exa mple.eclipse.org/schema/myext.xsdmyext.xsd">"http://example.eclipse.org/schema/base.xsd
base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd"</a>&gt;
&lt;entry xmlns=""&gt;
&lt;name&gt;entry1&lt;/name&gt;
&lt;extension&gt;&lt;myext:info&gt;
&lt;content xmlns=""&gt;"This string is content"&lt;/content&gt;
&lt;/myext:info&gt;&lt;/extension&gt;
&lt;/entry&gt;
&lt;/root&gt;

----------- end useextensioninbase.xml -------------------

Is there a way (when I arrive at the &lt;extension&gt; entry) to tell EMF that the
contents should be serialized as another embedded EMF model?

Yep. Just get used to working with the features of the document root class
of the other models...

Thanks,

Jay





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

--------------090005080300020500070400--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Handling embedded XML schema [message #424240 is a reply to message #424215] Tue, 21 October 2008 13:57 Go to previous messageGo to next message
Jay Lawrence is currently offline Jay LawrenceFriend
Messages: 7
Registered: July 2009
Junior Member
I'm still having issues getting an actual Info object created out of the
AnyType Object. When I attempt to get a list of DOCUMENT_ROOT__INFO objects,
I get an empty list. These are ANY_TYPE__ANY objects.

I've modified my doSwitch to print what I believe is the relevant
information. Below is the listing lines starting with //=> Are the output of
the print statements interspersed with the listing. they end with <=//

Thanks again,

Jay


--------- begin doSwitch Case

public Object caseExtension (Extension object) {

System.out.println("EXTENSION: " + object.toString());
//=> EXTENSION: org.eclipse.example.schema.base.impl.ExtensionImpl@18aaa1e
(any: [myext.xsd:info=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@a6aeed
(mixed: [content=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@126804e
(mixed: [ecore.xml.type:text="This string is content"], anyAttribute:
null)], anyAttribute: null)]) <=//


FeatureMap baseMap = object.getAny();

// Try to get Info documents
List<Entry> infoList =
baseMap.list(MyextPackage.Literals.DOCUMENT_ROOT__INFO);
System.out.println("Size of Info List = " + infoList.size());
//=> Size of Info List = 0 <=//

// Get the Any features => Prints 1
List<AnyType> anyList =
baseMap.list(XMLTypePackage.Literals.ANY_TYPE__ANY);
System.out.println("Size of Any List = " + anyList.size());
//=> Size of Any List = 1 <=//

// Iterate through the whole map and see what is there
Iterator<FeatureMap.Entry> mapIter = baseMap.iterator();
while (mapIter.hasNext()) {
FeatureMap.Entry entry = mapIter.next();

EStructuralFeature entryFeature = entry.getEStructuralFeature();
System.out.println("entry StructuralFeature: " + entryFeature);
//=> entry StructuralFeature:
org.eclipse.emf.ecore.impl.EReferenceImpl@ed0338 (name: info) (ordered:
true, unique: true, lowerBound: 0, upperBound: -2) (changeable: true,
volatile: true, transient: true, defaultValueLiteral: null, unsettable:
false, derived: true) (containment: true, resolveProxies: false) <=//

EObject entryValue = (EObject) entry.getValue();
System.out.println("entry Value: " + entryValue);
//<= entry Value: org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@a6aeed
(mixed: [content=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@126804e
(mixed: [ecore.xml.type:text="This string is content"], anyAttribute:
null)], anyAttribute: null) <=//

EClass entryClass = entryValue.eClass();
System.out.println("entry Class: " + entryClass.getName() + " " +
entryClass.getEPackage());
//<= entry Class: AnyType
org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl@471e30 (name: type)
(nsURI: http://www.eclipse.org/emf/2003/XMLType, nsPrefix: ecore.xml.type)
<=//

// So how do I get to something like
// Info info = entry.???
}
return Boolean.FALSE;
}


"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:gdipfc$fq7$1@build.eclipse.org...
Jay,

Comments below.

Jay Lawrence wrote:
Thanks Ed,

The interface to FeatureMaps baffles me ...

And I thought it was so intuitively obvious it didn't need Javadoc. :-P

You're explanation makes sense for creating such a document. Can you help me
get the value back out?

Jeesh, you want to get it out too? Hehehe.

I'm in a doSwitch for the Extension object and have code like:

public Object caseExtension (Extension object) {
System.out.println("Extension: " + object.toString());
Extension ext = object;
FeatureMap baseMap = ext.getAny();

// Now how do I get an Info Object? // The following gives me a Casting
exception
Info info = baseMap.get(MyextPackage.Literals.DOCUMENT_ROOT__INFO,
true);

Because there can be a whole list of them, so you need to ask for the whole
list and then iterate over it:

baseMap.list(MyextPackage.Literals.DOCUMENT_ROOT__INFO)

If the wildcard couldn't repeat then what you has before would have been
correct. This is why we have FeatureMapUtil.isMany; whether the document
root feature is allowed to repeat or not is relative to the multiplicity of
the feature map that holds it...

It's all so complicated, but that's XML Schema for you...

System.out.println("INFO: " + info.toString());
return Boolean.FALSE;
}

Sincerely,

Jay



"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:gdik42$rcl$1@build.eclipse.org...
Jay,

Comments below.


Jay Lawrence wrote:
I'm working with an XML schema (beyond my control) that allows "extension"
elements so that users of the schema have a place to put arbitrary embedded
XML content.

The schema below is a representative sample. It contains a Root object, that
can have an unbounded number of Entry elements, each of which has a Name and
an Extension opportunity.

An example of the form of schema is:

------------ begin base.xsd -------------

<xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:base="http://example.eclipse.org/schema/base.xsd"
targetNamespace="http://example.eclipse.org/schema/base.xsd">

<xsd:complexType name="Extension">
<xsd:sequence>
<xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Entry">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="extension" type="base:Extension"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Root">
<xsd:sequence>
<xsd:element name="entry" maxOccurs="unbounded"
type="base:Entry"></xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="root" type="base:Root"></xsd:element>

</xsd:schema>

----------- end base.xsd ---------------

The key element here is the:

<xsd:any namespace="##any" processContents="lax"
maxOccurs="unbounded"/>

This is converted into a Feature Map in the generated model as documented in
the EMF book (I have the latest September version of the Rough Cut).

It should be in print in December. Woo hoo!

If I have a second schema that I want to place in this extension location
and read in as an EMF model how can this be accomplished?

Generally you'd do:

extension.getAny().add(XyzPacakge.Literals.DOCUMENT_ROOT__<element >,
<value-of-element's-type>).

Or this would accomplish the same:

extension.getAny().list(XyzPacakge.Literals.DOCUMENT_ROOT__<element >).add(<value-of-element's-type>).
I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
dynamic ecore model that I have to use reflection on to get at. I instead
want to use my own EMF model for the second embedded schema.

For completeness. Here is an example of a second schema:

------------- begin myext.xsd --------------

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
targetNamespace="http://example.eclipse.org/schema/myext.xsd">

<xsd:complexType name="Info">
<xsd:sequence>
<xsd:element name="content" type="xsd:string"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="info" type="myext:Info"/>

</xsd:schema>

------------- end myext.xsd --------------------

Substitute INFO above and create an instance of Info for the value.

And a document that uses the base schema and the extension schema as an
embedded element

----------- begin useextensioninbase.xml ---------------------

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
xmlns="http://example.eclipse.org/schema/base.xsd"
xsi:schemaLocation="http://example.eclipse.org/schema/base.xsd
base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd">
<entry xmlns="">
<name>entry1</name>
<extension><myext:info>
<content xmlns="">"This string is content"</content>
</myext:info></extension>
</entry>
</root>

----------- end useextensioninbase.xml -------------------

Is there a way (when I arrive at the <extension> entry) to tell EMF that the
contents should be serialized as another embedded EMF model?

Yep. Just get used to working with the features of the document root class
of the other models...

Thanks,

Jay
Re: Handling embedded XML schema [message #424242 is a reply to message #424240] Tue, 21 October 2008 14:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Jay,

Comments below.

Jay Lawrence wrote:
> I'm still having issues getting an actual Info object created out of the
> AnyType Object. When I attempt to get a list of DOCUMENT_ROOT__INFO objects,
> I get an empty list. These are ANY_TYPE__ANY objects.
>
> I've modified my doSwitch to print what I believe is the relevant
> information. Below is the listing lines starting with //=> Are the output of
> the print statements interspersed with the listing. they end with <=//
>
> Thanks again,
>
> Jay
>
>
> --------- begin doSwitch Case
>
> public Object caseExtension (Extension object) {
>
> System.out.println("EXTENSION: " + object.toString());
> //=> EXTENSION: org.eclipse.example.schema.base.impl.ExtensionImpl@18aaa1e
> (any: [myext.xsd:info=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@a6aeed
>
I'd expect this if the package for the namespace of the "info" element
in the XML isn't registered. Are you running stand-alone or in an
Eclipse application?
> (mixed: [content=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@126804e
> (mixed: [ecore.xml.type:text="This string is content"], anyAttribute:
> null)], anyAttribute: null)]) <=//
>
>
> FeatureMap baseMap = object.getAny();
>
> // Try to get Info documents
> List<Entry> infoList =
> baseMap.list(MyextPackage.Literals.DOCUMENT_ROOT__INFO);
> System.out.println("Size of Info List = " + infoList.size());
> //=> Size of Info List = 0 <=//
>
If the actual feature in the list is a demand created one (which is
allowed by the "lax" wildcard) then that's a different feature from the
strongly typed generated one.
> // Get the Any features => Prints 1
> List<AnyType> anyList =
> baseMap.list(XMLTypePackage.Literals.ANY_TYPE__ANY);
> System.out.println("Size of Any List = " + anyList.size());
> //=> Size of Any List = 1 <=//
>
> // Iterate through the whole map and see what is there
> Iterator<FeatureMap.Entry> mapIter = baseMap.iterator();
> while (mapIter.hasNext()) {
> FeatureMap.Entry entry = mapIter.next();
>
> EStructuralFeature entryFeature = entry.getEStructuralFeature();
> System.out.println("entry StructuralFeature: " + entryFeature);
> //=> entry StructuralFeature:
> org.eclipse.emf.ecore.impl.EReferenceImpl@ed0338 (name: info) (ordered:
> true, unique: true, lowerBound: 0, upperBound: -2) (changeable: true,
> volatile: true, transient: true, defaultValueLiteral: null, unsettable:
> false, derived: true) (containment: true, resolveProxies: false) <=//
>
> EObject entryValue = (EObject) entry.getValue();
> System.out.println("entry Value: " + entryValue);
> //<= entry Value: org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@a6aeed
> (mixed: [content=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@126804e
> (mixed: [ecore.xml.type:text="This string is content"], anyAttribute:
> null)], anyAttribute: null) <=//
>
Yes, this is definitely based on demand created metadata.
> EClass entryClass = entryValue.eClass();
> System.out.println("entry Class: " + entryClass.getName() + " " +
> entryClass.getEPackage());
> //<= entry Class: AnyType
> org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl@471e30 (name: type)
> (nsURI: http://www.eclipse.org/emf/2003/XMLType, nsPrefix: ecore.xml.type)
> <=//
>
> // So how do I get to something like
> // Info info = entry.???
> }
> return Boolean.FALSE;
> }
>
If you're running standalone, it's very important to access the
XyzPackage.eINSTANCE for the package the "info" element before you read
the instance. I.e., it's important that the package for the "info"
element is registered in the EPackage.Registry.INSTANCE.
>
> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
> news:gdipfc$fq7$1@build.eclipse.org...
> Jay,
>
> Comments below.
>
> Jay Lawrence wrote:
> Thanks Ed,
>
> The interface to FeatureMaps baffles me ...
>
> And I thought it was so intuitively obvious it didn't need Javadoc. :-P
>
> You're explanation makes sense for creating such a document. Can you help me
> get the value back out?
>
> Jeesh, you want to get it out too? Hehehe.
>
> I'm in a doSwitch for the Extension object and have code like:
>
> public Object caseExtension (Extension object) {
> System.out.println("Extension: " + object.toString());
> Extension ext = object;
> FeatureMap baseMap = ext.getAny();
>
> // Now how do I get an Info Object? // The following gives me a Casting
> exception
> Info info = baseMap.get(MyextPackage.Literals.DOCUMENT_ROOT__INFO,
> true);
>
> Because there can be a whole list of them, so you need to ask for the whole
> list and then iterate over it:
>
> baseMap.list(MyextPackage.Literals.DOCUMENT_ROOT__INFO)
>
> If the wildcard couldn't repeat then what you has before would have been
> correct. This is why we have FeatureMapUtil.isMany; whether the document
> root feature is allowed to repeat or not is relative to the multiplicity of
> the feature map that holds it...
>
> It's all so complicated, but that's XML Schema for you...
>
> System.out.println("INFO: " + info.toString());
> return Boolean.FALSE;
> }
>
> Sincerely,
>
> Jay
>
>
>
> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
> news:gdik42$rcl$1@build.eclipse.org...
> Jay,
>
> Comments below.
>
>
> Jay Lawrence wrote:
> I'm working with an XML schema (beyond my control) that allows "extension"
> elements so that users of the schema have a place to put arbitrary embedded
> XML content.
>
> The schema below is a representative sample. It contains a Root object, that
> can have an unbounded number of Entry elements, each of which has a Name and
> an Extension opportunity.
>
> An example of the form of schema is:
>
> ------------ begin base.xsd -------------
>
> <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema
> xmlns:base="http://example.eclipse.org/schema/base.xsd"
> targetNamespace="http://example.eclipse.org/schema/base.xsd">
>
> <xsd:complexType name="Extension">
> <xsd:sequence>
> <xsd:any namespace="##any" processContents="lax"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="Entry">
> <xsd:sequence>
> <xsd:element name="name" type="xsd:string"/>
> <xsd:element name="extension" type="base:Extension"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="Root">
> <xsd:sequence>
> <xsd:element name="entry" maxOccurs="unbounded"
> type="base:Entry"></xsd:element>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:element name="root" type="base:Root"></xsd:element>
>
> </xsd:schema>
>
> ----------- end base.xsd ---------------
>
> The key element here is the:
>
> <xsd:any namespace="##any" processContents="lax"
> maxOccurs="unbounded"/>
>
> This is converted into a Feature Map in the generated model as documented in
> the EMF book (I have the latest September version of the Rough Cut).
>
> It should be in print in December. Woo hoo!
>
> If I have a second schema that I want to place in this extension location
> and read in as an EMF model how can this be accomplished?
>
> Generally you'd do:
>
> extension.getAny().add(XyzPacakge.Literals.DOCUMENT_ROOT__<element >,
> <value-of-element's-type>).
>
> Or this would accomplish the same:
>
> extension.getAny().list(XyzPacakge.Literals.DOCUMENT_ROOT__<element >).add(<value-of-element's-type>).
> I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
> dynamic ecore model that I have to use reflection on to get at. I instead
> want to use my own EMF model for the second embedded schema.
>
> For completeness. Here is an example of a second schema:
>
> ------------- begin myext.xsd --------------
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
> targetNamespace="http://example.eclipse.org/schema/myext.xsd">
>
> <xsd:complexType name="Info">
> <xsd:sequence>
> <xsd:element name="content" type="xsd:string"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:element name="info" type="myext:Info"/>
>
> </xsd:schema>
>
> ------------- end myext.xsd --------------------
>
> Substitute INFO above and create an instance of Info for the value.
>
> And a document that uses the base schema and the extension schema as an
> embedded element
>
> ----------- begin useextensioninbase.xml ---------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
> xmlns="http://example.eclipse.org/schema/base.xsd"
> xsi:schemaLocation="http://example.eclipse.org/schema/base.xsd
> base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd">
> <entry xmlns="">
> <name>entry1</name>
> <extension><myext:info>
> <content xmlns="">"This string is content"</content>
> </myext:info></extension>
> </entry>
> </root>
>
> ----------- end useextensioninbase.xml -------------------
>
> Is there a way (when I arrive at the <extension> entry) to tell EMF that the
> contents should be serialized as another embedded EMF model?
>
> Yep. Just get used to working with the features of the document root class
> of the other models...
>
> Thanks,
>
> Jay
>
>
>
>
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Handling embedded XML schema [message #424243 is a reply to message #424242] Tue, 21 October 2008 15:22 Go to previous message
Jay Lawrence is currently offline Jay LawrenceFriend
Messages: 7
Registered: July 2009
Junior Member
Ed,

Once again we must all be humble in your presence ...

As you already know, I hadn't accessed the MyextPackage.eInstance. I usually
bury this in a class that handles all the Resources for any given model.
Since I wasn't creating an explicit resource, I never initialized that
class.

I've just created an empty MyextResource to get it initilialized. Now my
application prints:

--------- begin print ----------
EXTENSION: org.eclipse.example.schema.base.impl.ExtensionImpl@1efb836 (any:
[myext:info=org.eclipse.example.schema.myext.impl.InfoImpl@126e85f (content:
["This string is content"])])

Size of Info List = 1

Size of Any List = 1

entry StructuralFeature: org.eclipse.emf.ecore.impl.EReferenceImpl@ba6c83
(name: info) (ordered: true, unique: true, lowerBound: 0, upperBound: -2)
(changeable: true, volatile: true, transient: true, defaultValueLiteral:
null, unsettable: false, derived: true) (containment: true, resolveProxies:
false)

entry Value: org.eclipse.example.schema.myext.impl.InfoImpl@126e85f
(content: ["This string is content"])

entry Class: Info
org.eclipse.example.schema.myext.impl.MyextPackageImpl@161f10f (name: myext)
(nsURI: http://example.eclipse.org/schema/myext.xsd, nsPrefix: myext)

----------- end print

So I can just extract the Info object directly from the featureMap or the
originally suggested List.

The way this will work in production is that many extensions may be done by
multiple parties who will each register their schema so understanding the
multiplicity of the featureMap and how to access both explicit and derived
models was a valuable exercised.

I always say that it is a good day when I learn something new. With your
help, I managed to accomplish that before noon today....

..... Maybe I should take the rest of the day off?

Thanks again,

Jay



"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:gdkqh5$uje$1@build.eclipse.org...
> Jay,
>
> Comments below.
>
> Jay Lawrence wrote:
>> I'm still having issues getting an actual Info object created out of the
>> AnyType Object. When I attempt to get a list of DOCUMENT_ROOT__INFO
>> objects, I get an empty list. These are ANY_TYPE__ANY objects.
>>
>> I've modified my doSwitch to print what I believe is the relevant
>> information. Below is the listing lines starting with //=> Are the output
>> of the print statements interspersed with the listing. they end with <=//
>>
>> Thanks again,
>>
>> Jay
>>
>>
>> --------- begin doSwitch Case
>>
>> public Object caseExtension (Extension object) {
>>
>> System.out.println("EXTENSION: " + object.toString());
>> //=> EXTENSION:
>> org.eclipse.example.schema.base.impl.ExtensionImpl@18aaa1e (any:
>> [myext.xsd:info=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@a6aeed
> I'd expect this if the package for the namespace of the "info" element in
> the XML isn't registered. Are you running stand-alone or in an Eclipse
> application?
>> (mixed: [content=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@126804e
>> (mixed: [ecore.xml.type:text="This string is content"], anyAttribute:
>> null)], anyAttribute: null)]) <=//
>>
>>
>> FeatureMap baseMap = object.getAny();
>>
>> // Try to get Info documents
>> List<Entry> infoList =
>> baseMap.list(MyextPackage.Literals.DOCUMENT_ROOT__INFO);
>> System.out.println("Size of Info List = " + infoList.size());
>> //=> Size of Info List = 0 <=//
>>
> If the actual feature in the list is a demand created one (which is
> allowed by the "lax" wildcard) then that's a different feature from the
> strongly typed generated one.
>> // Get the Any features => Prints 1
>> List<AnyType> anyList =
>> baseMap.list(XMLTypePackage.Literals.ANY_TYPE__ANY);
>> System.out.println("Size of Any List = " + anyList.size());
>> //=> Size of Any List = 1 <=//
>>
>> // Iterate through the whole map and see what is there
>> Iterator<FeatureMap.Entry> mapIter = baseMap.iterator();
>> while (mapIter.hasNext()) {
>> FeatureMap.Entry entry = mapIter.next();
>>
>> EStructuralFeature entryFeature = entry.getEStructuralFeature();
>> System.out.println("entry StructuralFeature: " + entryFeature);
>> //=> entry StructuralFeature:
>> org.eclipse.emf.ecore.impl.EReferenceImpl@ed0338 (name: info) (ordered:
>> true, unique: true, lowerBound: 0, upperBound: -2) (changeable: true,
>> volatile: true, transient: true, defaultValueLiteral: null, unsettable:
>> false, derived: true) (containment: true, resolveProxies: false) <=//
>>
>> EObject entryValue = (EObject) entry.getValue();
>> System.out.println("entry Value: " + entryValue);
>> //<= entry Value: org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@a6aeed
>> (mixed: [content=org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl@126804e
>> (mixed: [ecore.xml.type:text="This string is content"], anyAttribute:
>> null)], anyAttribute: null) <=//
>>
> Yes, this is definitely based on demand created metadata.
>> EClass entryClass = entryValue.eClass();
>> System.out.println("entry Class: " + entryClass.getName() + " " +
>> entryClass.getEPackage());
>> //<= entry Class: AnyType
>> org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl@471e30 (name:
>> type) (nsURI: http://www.eclipse.org/emf/2003/XMLType, nsPrefix:
>> ecore.xml.type) <=//
>>
>> // So how do I get to something like
>> // Info info = entry.???
>> }
>> return Boolean.FALSE;
>> }
>>
> If you're running standalone, it's very important to access the
> XyzPackage.eINSTANCE for the package the "info" element before you read
> the instance. I.e., it's important that the package for the "info"
> element is registered in the EPackage.Registry.INSTANCE.
>>
>> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
>> news:gdipfc$fq7$1@build.eclipse.org...
>> Jay,
>>
>> Comments below.
>>
>> Jay Lawrence wrote:
>> Thanks Ed,
>>
>> The interface to FeatureMaps baffles me ...
>>
>> And I thought it was so intuitively obvious it didn't need Javadoc. :-P
>>
>> You're explanation makes sense for creating such a document. Can you help
>> me
>> get the value back out?
>>
>> Jeesh, you want to get it out too? Hehehe.
>>
>> I'm in a doSwitch for the Extension object and have code like:
>>
>> public Object caseExtension (Extension object) {
>> System.out.println("Extension: " + object.toString());
>> Extension ext = object;
>> FeatureMap baseMap = ext.getAny();
>>
>> // Now how do I get an Info Object? // The following gives me a
>> Casting
>> exception
>> Info info = baseMap.get(MyextPackage.Literals.DOCUMENT_ROOT__INFO,
>> true);
>>
>> Because there can be a whole list of them, so you need to ask for the
>> whole list and then iterate over it:
>>
>> baseMap.list(MyextPackage.Literals.DOCUMENT_ROOT__INFO)
>>
>> If the wildcard couldn't repeat then what you has before would have been
>> correct. This is why we have FeatureMapUtil.isMany; whether the document
>> root feature is allowed to repeat or not is relative to the multiplicity
>> of the feature map that holds it...
>>
>> It's all so complicated, but that's XML Schema for you...
>>
>> System.out.println("INFO: " + info.toString());
>> return Boolean.FALSE;
>> }
>>
>> Sincerely,
>>
>> Jay
>>
>>
>>
>> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
>> news:gdik42$rcl$1@build.eclipse.org...
>> Jay,
>>
>> Comments below.
>>
>>
>> Jay Lawrence wrote:
>> I'm working with an XML schema (beyond my control) that allows
>> "extension"
>> elements so that users of the schema have a place to put arbitrary
>> embedded
>> XML content.
>>
>> The schema below is a representative sample. It contains a Root object,
>> that
>> can have an unbounded number of Entry elements, each of which has a Name
>> and
>> an Extension opportunity.
>>
>> An example of the form of schema is:
>>
>> ------------ begin base.xsd -------------
>>
>> <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema
>> xmlns:base="http://example.eclipse.org/schema/base.xsd"
>> targetNamespace="http://example.eclipse.org/schema/base.xsd">
>>
>> <xsd:complexType name="Extension">
>> <xsd:sequence>
>> <xsd:any namespace="##any" processContents="lax"
>> maxOccurs="unbounded"/>
>> </xsd:sequence>
>> </xsd:complexType>
>>
>> <xsd:complexType name="Entry">
>> <xsd:sequence>
>> <xsd:element name="name" type="xsd:string"/>
>> <xsd:element name="extension" type="base:Extension"/>
>> </xsd:sequence>
>> </xsd:complexType>
>>
>> <xsd:complexType name="Root">
>> <xsd:sequence>
>> <xsd:element name="entry" maxOccurs="unbounded"
>> type="base:Entry"></xsd:element>
>> </xsd:sequence>
>> </xsd:complexType>
>>
>> <xsd:element name="root" type="base:Root"></xsd:element>
>>
>> </xsd:schema>
>>
>> ----------- end base.xsd ---------------
>>
>> The key element here is the:
>>
>> <xsd:any namespace="##any" processContents="lax"
>> maxOccurs="unbounded"/>
>>
>> This is converted into a Feature Map in the generated model as documented
>> in
>> the EMF book (I have the latest September version of the Rough Cut).
>>
>> It should be in print in December. Woo hoo!
>>
>> If I have a second schema that I want to place in this extension location
>> and read in as an EMF model how can this be accomplished?
>>
>> Generally you'd do:
>>
>> extension.getAny().add(XyzPacakge.Literals.DOCUMENT_ROOT__<element >,
>> <value-of-element's-type>).
>>
>> Or this would accomplish the same:
>>
>> extension.getAny().list(XyzPacakge.Literals.DOCUMENT_ROOT__<element >).add(<value-of-element's-type>).
>> I've looked at the "GenericXMLResourceFactoryImpl" but this will create a
>> dynamic ecore model that I have to use reflection on to get at. I instead
>> want to use my own EMF model for the second embedded schema.
>>
>> For completeness. Here is an example of a second schema:
>>
>> ------------- begin myext.xsd --------------
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>
>> xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
>>
>> targetNamespace="http://example.eclipse.org/schema/myext.xsd">
>>
>> <xsd:complexType name="Info">
>> <xsd:sequence>
>> <xsd:element name="content" type="xsd:string"
>> maxOccurs="unbounded"/>
>> </xsd:sequence>
>> </xsd:complexType>
>>
>> <xsd:element name="info" type="myext:Info"/>
>>
>> </xsd:schema>
>>
>> ------------- end myext.xsd --------------------
>>
>> Substitute INFO above and create an instance of Info for the value.
>>
>> And a document that uses the base schema and the extension schema as an
>> embedded element
>>
>> ----------- begin useextensioninbase.xml ---------------------
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:myext="http://example.eclipse.org/schema/myext.xsd"
>> xmlns="http://example.eclipse.org/schema/base.xsd"
>> xsi:schemaLocation="http://example.eclipse.org/schema/base.xsd
>> base.xsd http://example.eclipse.org/schema/myext.xsd myext.xsd">
>> <entry xmlns="">
>> <name>entry1</name>
>> <extension><myext:info>
>> <content xmlns="">"This string is content"</content>
>> </myext:info></extension>
>> </entry>
>> </root>
>>
>> ----------- end useextensioninbase.xml -------------------
>>
>> Is there a way (when I arrive at the <extension> entry) to tell EMF that
>> the
>> contents should be serialized as another embedded EMF model?
>>
>> Yep. Just get used to working with the features of the document root
>> class
>> of the other models...
>>
>> Thanks,
>>
>> Jay
>>
>>
>>
>>
>>
>>
>>
>>
Previous Topic:Manipluate EMF MANIFEST.MF creation
Next Topic:copying a set of eobjects
Goto Forum:
  


Current Time: Fri Apr 19 22:21:30 GMT 2024

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

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

Back to the top