Skip to main content



      Home
Home » Modeling » EMF » How to get namespace attributes using Encore model?
How to get namespace attributes using Encore model? [message #403389] Wed, 06 September 2006 02:48 Go to next message
Eclipse UserFriend
I use EMF generate an Encore model from some schema files, such like below:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" ......>
<element name="module" type="scdl:Module"/>
<element name="component" type="scdl:Component"/>
<complexType name="Module">
<complexContent>
.......
</complexContent>
</complexType>
<complexType name="component">
<complexContent>
........
</complexContent>
</complexType>
.....
</schema>

There are maybe 2 kinds of xml files which correspond to module element
and component element respectively.

I want to parser a component element loaded from a xml file. But I can't
get the namespace attibutes. I find it could get XMLNSPrefixMap if I get a
DocumentRoot element(From API). How could I get the DocumentRoot element?
Do I need to get the DocumentRoot first if I want to get namespace
attibutes?

It could be parserd as a Component but can't be DocumentRoot when I load
the file like the following way(If I change Component to DocumentRoot ,it
will occur error):

Resource resource = new
XMLResourceImpl(URI.createFileURI("component.xml"));
XMLResource.XMLInfo info = new XMLInfoImpl();
info.setXMLRepresentation(XMLResource.XMLInfo.ELEMENT);
info.setName("component");
XMLResource.XMLMap map = new XMLMapImpl();
map.add(ScaPackage.eINSTANCE.getComponent(), info);
Map options = new HashMap();
options.put(XMLResource.OPTION_XML_MAP, map);
try {
resource.load(options);
} catch (IOException e) {
e.printStackTrace();
}
Component component = (Component)resource.getContents().get(0);


Thanks for any help!
Re: How to get namespace attributes using Encore model? [message #403393 is a reply to message #403389] Wed, 06 September 2006 09:14 Go to previous message
Eclipse UserFriend
Shan,

Use the popup in the Generator to "Generate Test Code" and then have a
look at the XyzExample.java in the generated *.tests project. It shows
how to create a new instance and how to load an existing instance.


Shan wrote:
> I use EMF generate an Encore model from some schema files, such like
> below:
> <?xml version="1.0" encoding="UTF-8"?>
> <schema xmlns="http://www.w3.org/2001/XMLSchema" ......>
> <element name="module" type="scdl:Module"/>
> <element name="component" type="scdl:Component"/>
> <complexType name="Module">
> <complexContent>
> .......
> </complexContent>
> </complexType>
> <complexType name="component">
> <complexContent>
> ........
> </complexContent>
> </complexType>
> .....
> </schema>
>
> There are maybe 2 kinds of xml files which correspond to module
> element and component element respectively.
>
> I want to parser a component element loaded from a xml file. But I
> can't get the namespace attibutes. I find it could get XMLNSPrefixMap
> if I get a DocumentRoot element(From API). How could I get the
> DocumentRoot element?
> Do I need to get the DocumentRoot first if I want to get namespace
> attibutes?
>
> It could be parserd as a Component but can't be DocumentRoot when I
> load the file like the following way(If I change Component to
> DocumentRoot ,it will occur error):
>
> Resource resource = new
> XMLResourceImpl(URI.createFileURI("component.xml"));
> XMLResource.XMLInfo info = new XMLInfoImpl();
> info.setXMLRepresentation(XMLResource.XMLInfo.ELEMENT);
> info.setName("component");
> XMLResource.XMLMap map = new XMLMapImpl();
> map.add(ScaPackage.eINSTANCE.getComponent(), info);
> Map options = new HashMap();
> options.put(XMLResource.OPTION_XML_MAP, map);
> try {
> resource.load(options);
> } catch (IOException e) {
> e.printStackTrace();
> }
> Component component = (Component)resource.getContents().get(0);
>
>
> Thanks for any help!
>
Previous Topic:hippie completion for properties?
Next Topic:when try to generate .genmodel from .ecore file, the ecore could not be loaded
Goto Forum:
  


Current Time: Wed Nov 05 07:46:51 EST 2025

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

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

Back to the top