|
|
Re: XML output unformatted with ecore:mixed [message #398423 is a reply to message #387056] |
Wed, 08 February 2006 15:03 |
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 |
Ed Merks Messages: 33212 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>
>>
>>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04635 seconds