Issue of EMF generated xml file namespace [message #649407] |
Wed, 19 January 2011 07:33 |
Robby Messages: 2 Registered: January 2011 |
Junior Member |
|
|
Hi,
I am using EMF to generate the model code based on schema file sip-app_1_1.xsd
since the sip-app.xsd import web-app_2_5.xsd, so the framework generated 2 sets of classes for me.
one is in namespce http://www.jcp.org/xml/ns/sipservlet
another in namespace http://java.sun.com/xml/ns/javaee
these xsd files are all standards schema files.
sip-app_1_1.xsd:
----------------------
<xs:schema xmlns="http://www.jcp.org/xml/ns/sipservlet"
targetNamespace="http://www.jcp.org/xml/ns/sipservlet"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
version="1.1">
<xs:import namespace="http://java.sun.com/xml/ns/javaee" schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"/>
...
web-app_2_5.xsd
----------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://java.sun.com/xml/ns/javaee"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="2.5">
I want to use the genered code for a sip.xml generation application.
The problem here is (shows as b bloew generated sip.xml)
For the element that defined in javaee namespace, it always have a prefix "javaee:"
<?xml version="1.0" encoding="UTF-8"?>
<sip-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.jcp.org/xml/ns/sipservlet"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://www.jcp.org/xml/ns/sipservlet http://www.jcp.org/xml/ns/sipservlet/sip-app_1_1.xsd"
version="1.1">
<servlet-selection>
<main-servlet>ServletName</main-servlet>
</servlet-selection>
<servlet>
<javaee:description>Desc</javaee:description>
<javaee:servlet-name>ServletName</javaee:servlet-name>
<javaee:servlet-class>ServletName</javaee:servlet-class>
<javaee:init-param>
<javaee:description>d</javaee:description>
<javaee:param-name>n</javaee:param-name>
<javaee:param-value>v</javaee:param-value>
</javaee:init-param>
</servlet>
</sip-app>
To remove these prefix, I tried add a extended metadata as bleow:
final ExtendedMetaData ext = new BasicExtendedMetaData(
ExtendedMetaData.ANNOTATION_URI,
EPackage.Registry.INSTANCE, new HashMap());
ext.setQualified(JavaeePackage.eINSTANCE, false);
it works, the result as below:
<?xml version="1.0" encoding="UTF-8"?>
<sip-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.jcp.org/xml/ns/sipservlet"
xsi:schemaLocation="http://www.jcp.org/xml/ns/sipservlet http://www.jcp.org/xml/ns/sipservlet/sip-app_1_1.xsd"
version="1.1">
<servlet-selection>
<main-servlet>ServletName</main-servlet>
</servlet-selection>
<servlet>
<description>desc</description>
<servlet-name>ServletName</servlet-name>
<servlet-class>ServletName</servlet-class>
<init-param>
<description>d</description>
<param-name>n</param-name>
<param-value>v</param-value>
</init-param>
</servlet>
</sip-app>
But if try to load the file back, exception thrown.
Caused by: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'description' not found. (
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeatu re(XMLHandler.java:1991)
so My questions are:
1. Is this exceptoin caused by the xml do not have a namespace xmlns:javaee="http://java.sun.com/xml/ns/javaee
so EMF can not load correct classes?
2. Since I can save without javaee namespace, how to load it back successfully?
Thank you!
|
|
|
Re: Issue of EMF generated xml file namespace [message #649548 is a reply to message #649407] |
Wed, 19 January 2011 16:41 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Robby,
Given you need access to two namespaces within one instance, and given
you can use xmlns="..." to default only one of the two namespace, you're
going to need prefixes to conform to the schemas. I assume you need
something that actually conforms to the schemas, but your second example
doesn't do that. It makes <description> look like it's in the wrong
namespace.
wang.robby@gmail.com wrote:
> Hi,
>
> I am using EMF to generate the model code based on schema file
> sip-app_1_1.xsd
> since the sip-app.xsd import web-app_2_5.xsd, so the framework
> generated 2 sets of classes for me.
> one is in namespce http://www.jcp.org/xml/ns/sipservlet another in
> namespace http://java.sun.com/xml/ns/javaee
>
> these xsd files are all standards schema files.
>
> sip-app_1_1.xsd:
> ----------------------
> <xs:schema xmlns="http://www.jcp.org/xml/ns/sipservlet"
> targetNamespace="http://www.jcp.org/xml/ns/sipservlet"
> xmlns:javaee="http://java.sun.com/xml/ns/javaee"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> version="1.1">
> <xs:import namespace="http://java.sun.com/xml/ns/javaee"
> schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"/>
> ..
>
> web-app_2_5.xsd
> ----------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://java.sun.com/xml/ns/javaee"
> xmlns:javaee="http://java.sun.com/xml/ns/javaee"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified"
> version="2.5">
>
>
> I want to use the genered code for a sip.xml generation application.
> The problem here is (shows as b bloew generated sip.xml)
> For the element that defined in javaee namespace, it always have a
> prefix "javaee:"
> <?xml version="1.0" encoding="UTF-8"?>
> <sip-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://www.jcp.org/xml/ns/sipservlet"
> xmlns:javaee="http://java.sun.com/xml/ns/javaee"
> xsi:schemaLocation="http://www.jcp.org/xml/ns/sipservlet
> http://www.jcp.org/xml/ns/sipservlet/sip-app_1_1.xsd" version="1.1">
> <servlet-selection>
> <main-servlet>ServletName</main-servlet>
> </servlet-selection>
> <servlet>
> <javaee:description>Desc</javaee:description>
> <javaee:servlet-name>ServletName</javaee:servlet-name>
> <javaee:servlet-class>ServletName</javaee:servlet-class>
> <javaee:init-param>
> <javaee:description>d</javaee:description>
> <javaee:param-name>n</javaee:param-name>
> <javaee:param-value>v</javaee:param-value>
> </javaee:init-param>
> </servlet>
> </sip-app>
>
> To remove these prefix, I tried add a extended metadata as bleow:
> final ExtendedMetaData ext = new BasicExtendedMetaData(
> ExtendedMetaData.ANNOTATION_URI,
> EPackage.Registry.INSTANCE, new HashMap());
> ext.setQualified(JavaeePackage.eINSTANCE, false);
>
> it works, the result as below:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <sip-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://www.jcp.org/xml/ns/sipservlet"
> xsi:schemaLocation="http://www.jcp.org/xml/ns/sipservlet
> http://www.jcp.org/xml/ns/sipservlet/sip-app_1_1.xsd" version="1.1">
> <servlet-selection>
> <main-servlet>ServletName</main-servlet>
> </servlet-selection>
> <servlet>
> <description>desc</description>
> <servlet-name>ServletName</servlet-name>
> <servlet-class>ServletName</servlet-class>
> <init-param>
> <description>d</description>
> <param-name>n</param-name>
> <param-value>v</param-value>
> </init-param>
> </servlet>
> </sip-app>
>
> But if try to load the file back, exception thrown.
> Caused by: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'description' not found. (
> at org.eclipse.emf.ecore.xmi.impl.XMLHandler.reportUnknownFeatu
> re(XMLHandler.java:1991)
>
> so My questions are:
> 1. Is this exceptoin caused by the xml do not have a namespace
> xmlns:javaee="http://java.sun.com/xml/ns/javaee
> so EMF can not load correct classes?
> 2. Since I can save without javaee namespace, how to load it back
> successfully?
>
> Thank you!
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Issue of EMF generated xml file namespace [message #649845 is a reply to message #649636] |
Thu, 20 January 2011 17:53 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Robby,
Do you really want to have instances that doesn't conform to your
schema? If that's the case, how about changing the schema (no target
namespace just a single one) to conform to the serialization you want?
In the end, anything you try to do to make this work will be equivalent
to that.
Robby wrote:
> Thank you Ed,
> in that case, can I do any mapping in EMF to let it know these
> elements like <description> belongs to "javaee" namespace and then
> EMF can load it? since I have 2 namespace and I can only set one to
> default namespace "".
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03356 seconds