Creating XML with n Models created using XSD [message #393060] |
Tue, 24 May 2005 12:45  |
Eclipse User |
|
|
|
Originally posted by: ismet.celebi.cs.tcd.ie
The goal is to create the following XML-File by using the emf created
methods.
<?xml version="1.0" encoding="UTF-8"?>
<o-ex:rights
xmlns:o-ex="http://odrl.net/1.1/ODRL-EX"
xmlns:o-dd="http://odrl.net/1.1/ODRL-DD">
<ex:agreement>
<ex:asset id="1">
<ex:context>
<dd:dLocation>URIofApplication</o-dd:dLocation>
</ex:context>
</ex:asset>
</ex:agreement>
</ex:rights>
So, now I have 2 models representing different XSD specifications.
The first model (o-ex) is used as the primary data model for my
application.
Up to now I created it so far:
<ex:rights xmlns:o-ex="http://odrl.net/1.1/ODRL-EX">
<ex:agreement>
<ex:asset id="1">
<ex:context/>
</ex:asset>
</ex:agreement>
</ex:rights>
Now I don't know, how to connect the two models to use now the
<o-dd:dLocation>
thats my code until now:
------------------------------------------------------------ ------
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map m = reg.getExtensionToFactoryMap();
m.put("parmamodel", new ExFactoryImpl());
ResourceSet resSet = new ResourceSetImpl();
URI.createURI("model/"+packageName+"model");
ExPackageImpl.init();
ExFactory factory = ExFactory.eINSTANCE;
RightsType rightstype = factory.createRightsType();
OfferAgreeType agreement = factory.createOfferAgreeType();
rightstype.getAgreement().add( agreement );
AssetType asset = factory.createAssetType();
agreement.getAsset().add(asset);
asset.setId("1");
ContextType conttype = factory.createContextType();
asset.getContext().add(conttype);
DocumentRoot docroot = ddfactory.createDocumentRoot();
URI fileURI = URI.createFileURI(System.getProperty("user.home")
+"/"
+"result.xml");
ExResourceFactoryImpl erfi = new ExResourceFactoryImpl();
Resource resource = erfi.createResource(fileURI);
resource.getContents().add( rightstype );
resource.save(Collections.EMPTY_MAP);
------------------------------------------------------------ ------
How to implement now the DD-Object dLocation ?
I tried to use an extra ddfactory like:
DdPackageImpl.init();
DdFactory ddfactory = DdFactory.eINSTANCE;
DocumentRoot docroot = ddfactory.createDocumentRoot();
docroot.setDLocation("URIofApplication");
because i couldn't merge it into the context part...
Cheers!
Ismet
|
|
|
Re: Creating XML with n Models created using XSD [message #393062 is a reply to message #393060] |
Tue, 24 May 2005 13:16   |
Eclipse User |
|
|
|
Ismet,
Since you haven't shown the schema, I don't know if the "context"
element's complex type has a getDLocation() feature or if there is a
wildcard being used? If the former, you can just do
setDLocation("...."). If the later, there will be a getAny feature
corresponding to the wildcard and you can do
context.getAny().add(DdPackage.eINSTANCE.getDocumentRoot_DLo cation(),
"....").
One trick you can always use to answer questions like this is to create
the XML, parse it, and see how it's represented...
Ismet Celebi wrote:
> The goal is to create the following XML-File by using the emf created
> methods.
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <o-ex:rights
> xmlns:o-ex="http://odrl.net/1.1/ODRL-EX"
> xmlns:o-dd="http://odrl.net/1.1/ODRL-DD">
>
> <ex:agreement>
> <ex:asset id="1">
> <ex:context>
> <dd:dLocation>URIofApplication</o-dd:dLocation>
> </ex:context>
> </ex:asset>
> </ex:agreement>
> </ex:rights>
>
> So, now I have 2 models representing different XSD specifications.
> The first model (o-ex) is used as the primary data model for my
> application.
>
> Up to now I created it so far:
>
> <ex:rights xmlns:o-ex="http://odrl.net/1.1/ODRL-EX">
> <ex:agreement>
> <ex:asset id="1">
> <ex:context/>
> </ex:asset>
> </ex:agreement>
> </ex:rights>
>
> Now I don't know, how to connect the two models to use now the
> <o-dd:dLocation>
>
> thats my code until now:
> ------------------------------------------------------------ ------
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> Map m = reg.getExtensionToFactoryMap();
> m.put("parmamodel", new ExFactoryImpl());
>
> ResourceSet resSet = new ResourceSetImpl();
> URI.createURI("model/"+packageName+"model");
>
> ExPackageImpl.init();
> ExFactory factory = ExFactory.eINSTANCE;
>
> RightsType rightstype = factory.createRightsType();
>
> OfferAgreeType agreement = factory.createOfferAgreeType();
> rightstype.getAgreement().add( agreement );
>
> AssetType asset = factory.createAssetType();
> agreement.getAsset().add(asset);
> asset.setId("1");
>
> ContextType conttype = factory.createContextType();
> asset.getContext().add(conttype);
>
> DocumentRoot docroot = ddfactory.createDocumentRoot();
>
> URI fileURI = URI.createFileURI(System.getProperty("user.home")
> +"/"
> +"result.xml");
> ExResourceFactoryImpl erfi = new ExResourceFactoryImpl();
> Resource resource = erfi.createResource(fileURI);
>
> resource.getContents().add( rightstype );
> resource.save(Collections.EMPTY_MAP);
> ------------------------------------------------------------ ------
>
> How to implement now the DD-Object dLocation ?
>
> I tried to use an extra ddfactory like:
>
> DdPackageImpl.init();
> DdFactory ddfactory = DdFactory.eINSTANCE;
> DocumentRoot docroot = ddfactory.createDocumentRoot();
> docroot.setDLocation("URIofApplication");
>
> because i couldn't merge it into the context part...
>
> Cheers!
> Ismet
>
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04507 seconds