Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XML output unformatted with ecore:mixed
XML output unformatted with ecore:mixed [message #387047] Fri, 13 August 2004 20:31 Go to next message
Mark Brodhun is currently offline Mark Brodhun
Messages: 30
Registered: July 2009
Member
I took the library.xsd example and added ecore:mixed="true" in ordet to
allow XML comments to be preserved.

The output of an instance document comes out flat on one line.
Here is the xsd I used.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.eclipse.org/Library"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:lib="http://www.example.eclipse.org/Library"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Book" ecore:mixed="true">
<xsd:sequence>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="pages" type="xsd:int"/>
<xsd:element name="category" type="lib:BookCategory"/>
<xsd:element name="author" type="xsd:anyURI"
ecore:reference="lib:Writer" ecore:opposite="books"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Writer" ecore:mixed="true">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="books"
type="xsd:anyURI" ecore:reference="lib:Book"
ecore:opposite="author"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Library" ecore:mixed="true">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="writers" type="lib:Writer"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="books" type="lib:Book"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="BookCategory">
<xsd:restriction base="xsd:NCName">
<xsd:enumeration value="Mystery"/>
<xsd:enumeration value="ScienceFiction"/>
<xsd:enumeration value="Biography"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Re: XML output unformatted with ecore:mixed [message #387056 is a reply to message #387047] Mon, 16 August 2004 12:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Mark,

Once you say it's mixed, you are responsible for the formatting. So if
you read in an instance, the instance formatting will be preserved, but
if you create an instance from scratch, you have to create the
formatting from scratch too.


Mark Brodhun wrote:

> I took the library.xsd example and added ecore:mixed="true" in ordet
> to allow XML comments to be preserved.
>
> The output of an instance document comes out flat on one line.
> Here is the xsd I used.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema targetNamespace="http://www.example.eclipse.org/Library"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:lib="http://www.example.eclipse.org/Library"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:complexType name="Book" ecore:mixed="true">
> <xsd:sequence>
> <xsd:element name="title" type="xsd:string"/>
> <xsd:element name="pages" type="xsd:int"/>
> <xsd:element name="category" type="lib:BookCategory"/>
> <xsd:element name="author" type="xsd:anyURI"
> ecore:reference="lib:Writer" ecore:opposite="books"/>
> </xsd:sequence>
> </xsd:complexType>
> <xsd:complexType name="Writer" ecore:mixed="true">
> <xsd:sequence>
> <xsd:element name="name" type="xsd:string"/>
> <xsd:element maxOccurs="unbounded" minOccurs="0" name="books"
> type="xsd:anyURI" ecore:reference="lib:Book"
> ecore:opposite="author"/>
> </xsd:sequence>
> </xsd:complexType>
> <xsd:complexType name="Library" ecore:mixed="true">
> <xsd:sequence>
> <xsd:element name="name" type="xsd:string"/>
> <xsd:element maxOccurs="unbounded" minOccurs="0"
> name="writers" type="lib:Writer"/>
> <xsd:element maxOccurs="unbounded" minOccurs="0"
> name="books" type="lib:Book"/>
> </xsd:sequence>
> </xsd:complexType>
> <xsd:simpleType name="BookCategory">
> <xsd:restriction base="xsd:NCName">
> <xsd:enumeration value="Mystery"/>
> <xsd:enumeration value="ScienceFiction"/>
> <xsd:enumeration value="Biography"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:schema>
Re: XML output unformatted with ecore:mixed [message #398423 is a reply to message #387056] Wed, 08 February 2006 15:03 Go to previous messageGo to next message
Jesper is currently offline Jesper
Messages: 1
Registered: July 2009
Junior Member
Hi, I am new at EMF, but have successfully created a model and am
currently reading data from it.

I am trying to use the ecore namespace as default when generation a
model from a schema. Heres the story.


During reading I found that the xsd :
<xs:element name="resulttype">
<xs:complexType mixed="true" />
</xs:element>


Does not allow me to access CDATA like banana

<resulttype>banana</resulttype>

in the generated code.

Adding the ecore namespace to the schema node
and putting mixed in this namespace fixed the problem

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore">
......
<xs:element name="resulttype">
<xs:complexType ecore:mixed="true" />
</xs:element>

now the generated code has the method getMixed() on which I can use the
getValue(0) to get CDATA contents, which is fine.

Back to the question : can I get the emf codegenerator to generate
getMixed as default or define the ecore namespace to be used as default

Regards, Jesper


Ed Merks wrote:
> Mark,
>
> Once you say it's mixed, you are responsible for the formatting. So if
> you read in an instance, the instance formatting will be preserved, but
> if you create an instance from scratch, you have to create the
> formatting from scratch too.
>
>
> Mark Brodhun wrote:
>
>> I took the library.xsd example and added ecore:mixed="true" in ordet
>> to allow XML comments to be preserved.
>>
>> The output of an instance document comes out flat on one line.
>> Here is the xsd I used.
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsd:schema targetNamespace="http://www.example.eclipse.org/Library"
>> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
>> xmlns:lib="http://www.example.eclipse.org/Library"
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>> <xsd:complexType name="Book" ecore:mixed="true">
>> <xsd:sequence>
>> <xsd:element name="title" type="xsd:string"/>
>> <xsd:element name="pages" type="xsd:int"/>
>> <xsd:element name="category" type="lib:BookCategory"/>
>> <xsd:element name="author" type="xsd:anyURI"
>> ecore:reference="lib:Writer" ecore:opposite="books"/>
>> </xsd:sequence>
>> </xsd:complexType>
>> <xsd:complexType name="Writer" ecore:mixed="true">
>> <xsd:sequence>
>> <xsd:element name="name" type="xsd:string"/>
>> <xsd:element maxOccurs="unbounded" minOccurs="0" name="books"
>> type="xsd:anyURI" ecore:reference="lib:Book"
>> ecore:opposite="author"/>
>> </xsd:sequence>
>> </xsd:complexType>
>> <xsd:complexType name="Library" ecore:mixed="true">
>> <xsd:sequence>
>> <xsd:element name="name" type="xsd:string"/>
>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>> name="writers" type="lib:Writer"/>
>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>> name="books" type="lib:Book"/>
>> </xsd:sequence>
>> </xsd:complexType>
>> <xsd:simpleType name="BookCategory">
>> <xsd:restriction base="xsd:NCName">
>> <xsd:enumeration value="Mystery"/>
>> <xsd:enumeration value="ScienceFiction"/>
>> <xsd:enumeration value="Biography"/>
>> </xsd:restriction>
>> </xsd:simpleType>
>> </xsd:schema>
>
Re: XML output unformatted with ecore:mixed [message #398425 is a reply to message #398423] Wed, 08 February 2006 16:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Jesper,

This was fixed by https://bugs.eclipse.org/bugs/show_bug.cgi?id=86118.


Jesper wrote:

> Hi, I am new at EMF, but have successfully created a model and am
> currently reading data from it.
>
> I am trying to use the ecore namespace as default when generation a
> model from a schema. Heres the story.
>
>
> During reading I found that the xsd :
> <xs:element name="resulttype">
> <xs:complexType mixed="true" />
> </xs:element>
>
>
> Does not allow me to access CDATA like banana
>
> <resulttype>banana</resulttype>
>
> in the generated code.
>
> Adding the ecore namespace to the schema node
> and putting mixed in this namespace fixed the problem
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore">
> .....
> <xs:element name="resulttype">
> <xs:complexType ecore:mixed="true" />
> </xs:element>
>
> now the generated code has the method getMixed() on which I can use
> the getValue(0) to get CDATA contents, which is fine.
>
> Back to the question : can I get the emf codegenerator to generate
> getMixed as default or define the ecore namespace to be used as default
>
> Regards, Jesper
>
>
> Ed Merks wrote:
>
>> Mark,
>>
>> Once you say it's mixed, you are responsible for the formatting. So
>> if you read in an instance, the instance formatting will be
>> preserved, but if you create an instance from scratch, you have to
>> create the formatting from scratch too.
>>
>>
>> Mark Brodhun wrote:
>>
>>> I took the library.xsd example and added ecore:mixed="true" in ordet
>>> to allow XML comments to be preserved.
>>>
>>> The output of an instance document comes out flat on one line.
>>> Here is the xsd I used.
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <xsd:schema targetNamespace="http://www.example.eclipse.org/Library"
>>> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
>>> xmlns:lib="http://www.example.eclipse.org/Library"
>>> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>>> <xsd:complexType name="Book" ecore:mixed="true">
>>> <xsd:sequence>
>>> <xsd:element name="title" type="xsd:string"/>
>>> <xsd:element name="pages" type="xsd:int"/>
>>> <xsd:element name="category" type="lib:BookCategory"/>
>>> <xsd:element name="author" type="xsd:anyURI"
>>> ecore:reference="lib:Writer" ecore:opposite="books"/>
>>> </xsd:sequence>
>>> </xsd:complexType>
>>> <xsd:complexType name="Writer" ecore:mixed="true">
>>> <xsd:sequence>
>>> <xsd:element name="name" type="xsd:string"/>
>>> <xsd:element maxOccurs="unbounded" minOccurs="0" name="books"
>>> type="xsd:anyURI" ecore:reference="lib:Book"
>>> ecore:opposite="author"/>
>>> </xsd:sequence>
>>> </xsd:complexType>
>>> <xsd:complexType name="Library" ecore:mixed="true">
>>> <xsd:sequence>
>>> <xsd:element name="name" type="xsd:string"/>
>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>> name="writers" type="lib:Writer"/>
>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>> name="books" type="lib:Book"/>
>>> </xsd:sequence>
>>> </xsd:complexType>
>>> <xsd:simpleType name="BookCategory">
>>> <xsd:restriction base="xsd:NCName">
>>> <xsd:enumeration value="Mystery"/>
>>> <xsd:enumeration value="ScienceFiction"/>
>>> <xsd:enumeration value="Biography"/>
>>> </xsd:restriction>
>>> </xsd:simpleType>
>>> </xsd:schema>
>>
>>
Re: XML output unformatted with ecore:mixed [message #1221683 is a reply to message #387047] Wed, 18 December 2013 08:26 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 59
Registered: August 2013
Member
Hi

Is it possible to allow comments for a complex type and to keep formatting working?
Re: XML output unformatted with ecore:mixed [message #1222158 is a reply to message #1221683] Thu, 19 December 2013 19:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Denis,

No, once you have mixed content, you have to control the format.

On 18/12/2013 9:26 AM, Denis Nikiforov wrote:
> Hi
>
> Is it possible to allow comments for a complex type and to keep
> formatting working?
Re: XML output unformatted with ecore:mixed [message #1222303 is a reply to message #387047] Fri, 20 December 2013 05:17 Go to previous message
Denis Nikiforov is currently offline Denis Nikiforov
Messages: 59
Registered: August 2013
Member
Thanks for reply!

For newbies like me: JDK 1.6 has a good XML support, and it's very easy to format XML even without 3rd party libraries. There are a lot of examples in a web.
Previous Topic:[EMF] [CDO] [Compare] [Bug?] Compare will not work with certan implementation of EStore
Next Topic:models referencing across editors
Goto Forum:
  


Current Time: Thu Sep 18 13:56:27 GMT 2014

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

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