Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » creating XML instances with multiple schemas
creating XML instances with multiple schemas [message #417643] Wed, 19 March 2008 15:58 Go to next message
Eclipse UserFriend
Originally posted by: fjgarcia.alumnos.upm.es

Hi

I have this three schemas, referenced between them, my objective is to
create XML instances of the first one:

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

targetNamespace=" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 "
xmlns=" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 "


xmlns:cbc=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "

elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="2.0">
<xsd:import
namespace=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
schemaLocation="../common/UBL-CommonBasicComponents-2.0.xsd "/>
<xsd:element name="CatalogueRequest" type="CatalogueRequest">
<xsd:annotation>
<xsd:documentation>This element MUST be conveyed as the root
element in any instance document based on this Schema
expression</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="CatalogueRequest">
<xsd:sequence>
<xsd:element ref="cbc:ID" minOccurs="1" maxOccurs="1">

</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>



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

targetNamespace=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "


xmlns:cbc=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "

xmlns:udt=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="2.0">
<!-- ===== Imports ===== -->
<xsd:import
namespace=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
schemaLocation="UnqualifiedDataTypeSchemaModule-2.0.xsd"/>

<xsd:element name="ID" type="cbc:ID"/>
<xsd:complexType name="ID">
<xsd:simpleContent>
<xsd:extension base="udt:IdentifierType"/>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
targetNamespace=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">


<xsd:complexType name="IdentifierType">
<xsd:simpleContent>
<xsd:extension base="xsd:normalizedString">
<xsd:attribute name="schemeID" type="xsd:normalizedString"
use="optional">

</xsd:attribute>
<xsd:attribute name="schemeName" type="xsd:string" use="optional">

</xsd:attribute>
<xsd:attribute name="schemeAgencyID"
type="xsd:normalizedString" use="optional">

</xsd:attribute>
<xsd:attribute name="schemeAgencyName" type="xsd:string"
use="optional">

</xsd:attribute>
<xsd:attribute name="schemeVersionID"
type="xsd:normalizedString" use="optional">

</xsd:attribute>
<xsd:attribute name="schemeDataURI" type="xsd:anyURI"
use="optional">

</xsd:attribute>
<xsd:attribute name="schemeURI" type="xsd:anyURI" use="optional">

</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>


I have created the ecore model and I have changed the name of the ecore
files to catalogueRequest, cbc and udt.ecore

In the properties editor I have changed:
NSPrefix from _2 to “”, “cbc” and “udt”
Name and EFactoryInstance from “_2” to “CatalogueRequest”, “CBC” and “UDT”

In the CatalogueRequest.genModel I perform the same change for each
package in the prefix property. Now it’s “CatalogueRequest”, “CBC” and
“UDT” instead of _2.

I generate the model code: It creates the packages
“….CatalogueRequest”, “CBC” and “UDT” with the correspondents .impl and
..util


Now want to create an XML instance document for the CatalogueRequest
element. For that I do the following

cbcFactory=new CBCFactoryImpl();
IDType id=cbcFactory.createIDType();
id.setValue(“CN758494”);

factory=new CatalogueRequestFactoryImpl();
CatalogueRequestType catalogueRequest=factory.createCatalogueRequestType();
CatalogueRequest.setID(id);


Resource resource =
new XMLResourceImpl(URI.createURI("../file.xml"));
resource.getContents().add(catalogueRequest);
try {
resource.save(null);
JFrame window=(JFrame)creator.getTopLevelAncestor();
window.dispose();
}

The document built is:

<?xml version="1.0" encoding="ASCII"?>
<CatalogueRequestType
xmlns=" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 ">
<iD value=" CN758494"/>
</CatalogueRequestType>

But the one I want to create should be like this other:

<?xml version="1.0" encoding="ASCII"?>
<CatalogueRequest xmlns=
" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 "
xmlns:cbc=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
">


<cbc:ID>CN758494</cbc:ID>

</CatalogueRequest>


Am I creating correctly the objects?
Is the problem in the how have I built the model code?

Any suggestion?

Thanks
Javier
Re: creating XML instances with multiple schemas [message #417644 is a reply to message #417643] Wed, 19 March 2008 16:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040506090907070109090603
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit

Javier,

Comments below.


Javier garcia wrote:
>
> Hi
>
> I have this three schemas, referenced between them, my objective is
> to create XML instances of the first one:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
> targetNamespace=" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 "
>
>
> xmlns=" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 "
>
>
> xmlns:cbc=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
>
>
> elementFormDefault="qualified"
> attributeFormDefault="unqualified"
> version="2.0">
> <xsd:import
> namespace=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
> schemaLocation="../common/UBL-CommonBasicComponents-2.0.xsd "/>
> <xsd:element name="CatalogueRequest" type="CatalogueRequest">
> <xsd:annotation>
> <xsd:documentation>This element MUST be conveyed as the root
> element in any instance document based on this Schema
> expression</xsd:documentation>
> </xsd:annotation>
> </xsd:element>
> <xsd:complexType name="CatalogueRequest">
> <xsd:sequence>
> <xsd:element ref="cbc:ID" minOccurs="1" maxOccurs="1">
>
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
> targetNamespace=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
>
>
>
> xmlns:cbc=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
>
>
> xmlns:udt=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
>
> elementFormDefault="qualified"
> attributeFormDefault="unqualified"
> version="2.0">
> <!-- ===== Imports ===== -->
> <xsd:import
> namespace=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
> schemaLocation="UnqualifiedDataTypeSchemaModule-2.0.xsd"/>
>
> <xsd:element name="ID" type="cbc:ID"/>
> <xsd:complexType name="ID">
> <xsd:simpleContent>
> <xsd:extension base="udt:IdentifierType"/>
> </xsd:simpleContent>
> </xsd:complexType>
> </xsd:schema>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema
> targetNamespace=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
>
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified">
>
>
> <xsd:complexType name="IdentifierType">
> <xsd:simpleContent>
> <xsd:extension base="xsd:normalizedString">
> <xsd:attribute name="schemeID" type="xsd:normalizedString"
> use="optional">
>
> </xsd:attribute>
> <xsd:attribute name="schemeName" type="xsd:string"
> use="optional">
>
> </xsd:attribute>
> <xsd:attribute name="schemeAgencyID"
> type="xsd:normalizedString" use="optional">
>
> </xsd:attribute>
> <xsd:attribute name="schemeAgencyName" type="xsd:string"
> use="optional">
>
> </xsd:attribute>
> <xsd:attribute name="schemeVersionID"
> type="xsd:normalizedString" use="optional">
>
> </xsd:attribute>
> <xsd:attribute name="schemeDataURI" type="xsd:anyURI"
> use="optional">
>
> </xsd:attribute>
> <xsd:attribute name="schemeURI" type="xsd:anyURI"
> use="optional">
>
> </xsd:attribute>
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>
> </xsd:schema>
>
>
> I have created the ecore model and I have changed the name of the
> ecore files to catalogueRequest, cbc and udt.ecore
>
> In the properties editor I have changed:
> NSPrefix from _2 to


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: creating XML instances with multiple schemas [message #417663 is a reply to message #417644] Thu, 20 March 2008 18:14 Go to previous message
Eclipse UserFriend
Originally posted by: fjgarcia.alumnos.upm.es

Hummm

I had not thought about the .test examples.
I also had that document but I didn't remember.
Now it works.
Thank you very much Ed

Javier

Ed Merks escribió:
> Javier,
>
> Comments below.
>
>
> Javier garcia wrote:
>>
>> Hi
>>
>> I have this three schemas, referenced between them, my objective is
>> to create XML instances of the first one:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>
>> targetNamespace=" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 "
>>
>>
>> xmlns=" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 "
>>
>>
>> xmlns:cbc=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
>>
>>
>> elementFormDefault="qualified"
>> attributeFormDefault="unqualified"
>> version="2.0">
>> <xsd:import
>> namespace=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
>> schemaLocation="../common/UBL-CommonBasicComponents-2.0.xsd "/>
>> <xsd:element name="CatalogueRequest" type="CatalogueRequest">
>> <xsd:annotation>
>> <xsd:documentation>This element MUST be conveyed as the root
>> element in any instance document based on this Schema
>> expression</xsd:documentation>
>> </xsd:annotation>
>> </xsd:element>
>> <xsd:complexType name="CatalogueRequest">
>> <xsd:sequence>
>> <xsd:element ref="cbc:ID" minOccurs="1" maxOccurs="1">
>>
>> </xsd:element>
>> </xsd:sequence>
>> </xsd:complexType>
>> </xsd:schema>
>>
>>
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>
>> targetNamespace=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
>>
>>
>>
>> xmlns:cbc=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
>>
>>
>> xmlns:udt=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
>>
>> elementFormDefault="qualified"
>> attributeFormDefault="unqualified"
>> version="2.0">
>> <!-- ===== Imports ===== -->
>> <xsd:import
>> namespace=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
>> schemaLocation="UnqualifiedDataTypeSchemaModule-2.0.xsd"/>
>>
>> <xsd:element name="ID" type="cbc:ID"/>
>> <xsd:complexType name="ID">
>> <xsd:simpleContent>
>> <xsd:extension base="udt:IdentifierType"/>
>> </xsd:simpleContent>
>> </xsd:complexType>
>> </xsd:schema>
>>
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsd:schema
>> targetNamespace=" urn:un:unece:uncefact:data:specification:UnqualifiedDataType sSchemaModule:2 "
>>
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>> elementFormDefault="qualified"
>> attributeFormDefault="unqualified">
>>
>>
>> <xsd:complexType name="IdentifierType">
>> <xsd:simpleContent>
>> <xsd:extension base="xsd:normalizedString">
>> <xsd:attribute name="schemeID" type="xsd:normalizedString"
>> use="optional">
>>
>> </xsd:attribute>
>> <xsd:attribute name="schemeName" type="xsd:string"
>> use="optional">
>>
>> </xsd:attribute>
>> <xsd:attribute name="schemeAgencyID"
>> type="xsd:normalizedString" use="optional">
>>
>> </xsd:attribute>
>> <xsd:attribute name="schemeAgencyName" type="xsd:string"
>> use="optional">
>>
>> </xsd:attribute>
>> <xsd:attribute name="schemeVersionID"
>> type="xsd:normalizedString" use="optional">
>>
>> </xsd:attribute>
>> <xsd:attribute name="schemeDataURI" type="xsd:anyURI"
>> use="optional">
>>
>> </xsd:attribute>
>> <xsd:attribute name="schemeURI" type="xsd:anyURI"
>> use="optional">
>>
>> </xsd:attribute>
>> </xsd:extension>
>> </xsd:simpleContent>
>> </xsd:complexType>
>> </xsd:schema>
>>
>>
>> I have created the ecore model and I have changed the name of the
>> ecore files to catalogueRequest, cbc and udt.ecore
>>
>> In the properties editor I have changed:
>> NSPrefix from _2 to “”, “cbc” and “udt”
>> Name and EFactoryInstance from “_2” to “CatalogueRequest”, “CBC” and
>> “UDT”
> There are ecore annotations you can put in the schema to specify this
> there, i.e, ecore:nsPrefix and ecore:package.
>
> XML Schema to Ecore Mapping
> < http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf>
>
>>
>> In the CatalogueRequest.genModel I perform the same change for each
>> package in the prefix property. Now it’s “CatalogueRequest”, “CBC” and
>> “UDT” instead of _2.
>>
>> I generate the model code: It creates the packages
>> “….CatalogueRequest”, “CBC” and “UDT” with the correspondents .impl
>> and .util
>>
>>
>> Now want to create an XML instance document for the CatalogueRequest
>> element. For that I do the following
>>
>> cbcFactory=new CBCFactoryImpl();
> No. Use CBCFactory.eINSTANCE. Try invoking Generate Test Code and have
> a look in the *.tests project for the CBCExample.java...
>> IDType id=cbcFactory.createIDType();
>> id.setValue(“CN758494”);
>>
>> factory=new CatalogueRequestFactoryImpl();
>> CatalogueRequestType
>> catalogueRequest=factory.createCatalogueRequestType();
>> CatalogueRequest.setID(id);
>>
>>
>> Resource resource =
>> new XMLResourceImpl(URI.createURI("../file.xml"));
> No. Use the generated resource factory or minimally be use you've set
> the same options that it sets. Again. Look at the example. Be sure to
> use a document root to properly control the root element.
>> resource.getContents().add(catalogueRequest);
>> try {
>> resource.save(null);
>> JFrame
>> window=(JFrame)creator.getTopLevelAncestor();
>> window.dispose();
>> }
>>
>> The document built is:
>>
>> <?xml version="1.0" encoding="ASCII"?>
>> <CatalogueRequestType
>> xmlns=" urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 ">
>> <iD value=" CN758494"/>
>> </CatalogueRequestType>
>>
>> But the one I want to create should be like this other:
>>
>> <?xml version="1.0" encoding="ASCII"?>
>> <CatalogueRequest xmlns=
>> " urn:oasis:names:specification:ubl:schema:xsd:CatalogueReques t-2 "
>> xmlns:cbc=" urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComp onents-2 "
>> ">
>>
>>
>> <cbc:ID>CN758494</cbc:ID>
>>
>> </CatalogueRequest>
>>
>>
>> Am I creating correctly the objects?
>> Is the problem in the how have I built the model code?
> There are quite a few mistakes. It will be good to look at the
> generated example to make sure you get it right.
>>
>> Any suggestion?
>>
>> Thanks
>> Javier
>
Previous Topic:How to generate compound document model using emf?
Next Topic:Error in generating code with Qname with older IDE
Goto Forum:
  


Current Time: Thu Apr 25 17:17:08 GMT 2024

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

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

Back to the top