Hallo,
die Kurzfassung:
Bei Benutzung von XSD und EMF bekomme ich im xml output
[XML]<uhrzeit value="23:54"/>[/XML], möchte aber haben [XML]<uhrzeit>23:54</uhrzeit>[/XML]
wie muss das XSD korrekt aussehen?
Detailliert:
zum Thema: Java Generierung mit EMF aus XSD
Umgebung: Eclipse 3.7 MDT
Kurz das doing in einem Eclipse EMF Project, z.B. Namens emf_party:
1. Ich nehme ein XSD (party.xsd)
2. Ich importiere das XSD im EMF Projekt (=> party.genmodel und Party.ecore werden generiert)
3. Ich lasse aus dem Model den Java Code generieren.
4. Ich benutze den JavaCode, um dann ein xml zu schreiben.
Nun zum Problem:
Im output bekomme ich:
[XML]
<uhrzeit value="23:54"/>
[/XML]
Ich möchte aber haben:
[XML]
<uhrzeit>23:54</uhrzeit>
[/XML]
Meine Frage:
Wie muss das Schema aussehen, damit ich den gewünschten Output bekomme?
Hier die Sourcen:
xsd:
[XML]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" ecore:nsPrefix="Party" ecoreackage="Party">
<xsd:simpleType name="datumType" ecore:name="DatumType">
<xsd:restriction base="xsd:string">
<xsdattern value="[0–3][0–9].[0–1][0–9].[0–9][0–9]"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="gastType" ecore:name="GastType">
<xsd:sequence>
<xsd:element name="getraenk" type="xsd:string"/>
<xsd:element name="zustand" type="zustandType"/>
<xsd:element name="uhrzeit">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:anyURI"/>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="partyType" ecore:name="PartyType">
<xsd:sequence>
<xsd:element name="gast" type="gastType"/>
</xsd:sequence>
<xsd:attribute name="datum" type="datumType"/>
</xsd:complexType>
<xsd:complexType name="zustandType" ecore:name="ZustandType">
<xsd:attribute name="ledig" type="xsd:boolean"/>
<xsd:attribute name="nuechtern" type="xsd:boolean"/>
</xsd:complexType>
</xsd:schema>
[/XML]
java code
result xml:
[XML]
<?xml version="1.0" encoding="ASCII"?>
<PartyartyType xmlnsarty="platform:/resource/emf_party/model/Party.xsd" datum="21.12.2112">
<gast getraenk="Bier">
<zustand ledig="true" nuechtern="false"/>
<uhrzeit value="23:54"/>
</gast>
</PartyartyType>
[/XML]
Gruß Farisola
die Kurzfassung:
Bei Benutzung von XSD und EMF bekomme ich im xml output
[XML]<uhrzeit value="23:54"/>[/XML], möchte aber haben [XML]<uhrzeit>23:54</uhrzeit>[/XML]
wie muss das XSD korrekt aussehen?
Detailliert:
zum Thema: Java Generierung mit EMF aus XSD
Umgebung: Eclipse 3.7 MDT
Kurz das doing in einem Eclipse EMF Project, z.B. Namens emf_party:
1. Ich nehme ein XSD (party.xsd)
2. Ich importiere das XSD im EMF Projekt (=> party.genmodel und Party.ecore werden generiert)
3. Ich lasse aus dem Model den Java Code generieren.
4. Ich benutze den JavaCode, um dann ein xml zu schreiben.
Nun zum Problem:
Im output bekomme ich:
[XML]
<uhrzeit value="23:54"/>
[/XML]
Ich möchte aber haben:
[XML]
<uhrzeit>23:54</uhrzeit>
[/XML]
Meine Frage:
Wie muss das Schema aussehen, damit ich den gewünschten Output bekomme?
Hier die Sourcen:
xsd:
[XML]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" ecore:nsPrefix="Party" ecoreackage="Party">
<xsd:simpleType name="datumType" ecore:name="DatumType">
<xsd:restriction base="xsd:string">
<xsdattern value="[0–3][0–9].[0–1][0–9].[0–9][0–9]"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="gastType" ecore:name="GastType">
<xsd:sequence>
<xsd:element name="getraenk" type="xsd:string"/>
<xsd:element name="zustand" type="zustandType"/>
<xsd:element name="uhrzeit">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:anyURI"/>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="partyType" ecore:name="PartyType">
<xsd:sequence>
<xsd:element name="gast" type="gastType"/>
</xsd:sequence>
<xsd:attribute name="datum" type="datumType"/>
</xsd:complexType>
<xsd:complexType name="zustandType" ecore:name="ZustandType">
<xsd:attribute name="ledig" type="xsd:boolean"/>
<xsd:attribute name="nuechtern" type="xsd:boolean"/>
</xsd:complexType>
</xsd:schema>
[/XML]
java code
Java:
private void createPartyXml() {
PartyFactoryImpl.init();
PartyFactory factory = PartyFactory.eINSTANCE;
PartyType party = factory.createPartyType();
party.setDatum("21.12.2112");
GastType gast = factory.createGastType();
gast.setGetraenk("Bier");
ZustandType zustand = factory.createZustandType();
zustand.setLedig(true);
zustand.setNuechtern(false);
gast.setZustand(zustand);
party.setGast(gast);
UhrzeitType uhrzeit = factory.createUhrzeitType();
uhrzeit.setValue("23:54");
gast.setUhrzeit(uhrzeit);
final Resource res = new XMLResourceImpl();
res.getContents().add(party);
FileOutputStream outputStream;
try {
outputStream = new FileOutputStream("party_result.xml");
res.save(outputStream, null);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
result xml:
[XML]
<?xml version="1.0" encoding="ASCII"?>
<PartyartyType xmlnsarty="platform:/resource/emf_party/model/Party.xsd" datum="21.12.2112">
<gast getraenk="Bier">
<zustand ledig="true" nuechtern="false"/>
<uhrzeit value="23:54"/>
</gast>
</PartyartyType>
[/XML]
Gruß Farisola