Home » Modeling » EMF » How to annotate attribute of type xsd:long to be of type LongObject in Ecore model
|
Re: How to annotate attribute of type xsd:long to be of type LongObject in Ecore model [message #427662 is a reply to message #427650] |
Wed, 25 February 2009 15:07 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Alexey,
Comments below.
koloale wrote:
> Hello, newsgroup
>
> I import Ecore model from xsd, where there is an attribute of type
> xsd:long. By default this attribute corresponds to long property in
> the generated code, but I want it to be java.lang.Long. Is there any
> way to annotate source xsd to achieve the desired result?
Hmmm. An xsd:element with nil="true" would do the trick, but you said
attribute.
> I searched for newsgroups, but ecore:instanceClass, ecore:type don't
> solve the problem, Also source schema should be used as standalone
> without ecore one to validate xml documents, i.e. type of attribute in
> xsd should be xsd:long.
You could use ecore:type, but you'd have to use ecore:ELongObject as the
type, and unfortunately you'd have to change the schema to import
Ecore.xsd from location
platform:/plugins/org.eclipse.emf.ecore/model/Ecore.xsd.
>
> Thanks, Alexey.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: How to annotate attribute of type xsd:long to be of type LongObject in Ecore model [message #427685 is a reply to message #427683] |
Thu, 26 February 2009 12:56 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------030806050400000904000001
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Koloale,
Given that the specification defines it like this:
XML Representation Summary: |annotation| Element Information Item
<annotation
id = ID
< http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#ID>
/{any attributes with non-schema namespace . . .}/>
/ Content: /(appinfo
<http://www.w3.org/TR/xmlschema-1/#element-appinfo> | documentation
<http://www.w3.org/TR/xmlschema-1/#element-documentation>)*
</annotation>
<appinfo
source = anyURI
< http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#anyURI>
/{any attributes with non-schema namespace . . .}/>
/ Content: /(/{any}/)*
</appinfo>
<documentation
source = anyURI
< http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#anyURI>
xml:lang = language
< http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#language>
/{any attributes with non-schema namespace . . .}/>
/ Content: /(/{any}/)*
</documentation>
And that the schema for schemas has this:
<xs:element name="appinfo" id="appinfo">
<xs:annotation>
<xs:documentation
source="http://www.w3.org/TR/xmlschema-1/#element-appinfo"/>
</xs:annotation>
<xs:complexType mixed="true">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:any processContents="lax"/>
</xs:sequence>
<xs:attribute name="source" type="xs:anyURI"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
</xs:element>
I'd say that validation error is bogus since clearly an appinfo is
allowed to have any attribute from any other namespace.
In other words, it sounds like a bug in the JAXP implementation you're
using.
koloale wrote:
> Hello, Ed!
> Ed Merks wrote:
>> You could use ecore:type, but you'd have to use ecore:ELongObject as
>> the type, and unfortunately you'd have to change the schema to import
>> Ecore.xsd from location
>> platform:/plugins/org.eclipse.emf.ecore/model/Ecore.xsd.
>
> I get failure of source xsd validation when I use ecore extensions,
> e.g. for <xsd:appinfo ecore:key="appinfo" source="teneo.jpa"> I get:
> "Attribute 'ecore:key' cannot appear in element 'appinfo'"). Maybe I
> need to set some special option in the validator. I use SAX parser for
> validation like that:
> // Create a JAXP SAXParserFactory and configure it
> SAXParserFactory spf = SAXParserFactory.newInstance();
> spf.setNamespaceAware(true);
> spf.setValidating(true);
>
> SAXParser saxParser = spf.newSAXParser();
> saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
> saxParser.setProperty(JAXP_SCHEMA_SOURCE, xmlSchema);
>
> XMLReader xmlReader = saxParser.getXMLReader();
> xmlReader.setContentHandler(new DefaultHandler());
> xmlReader.setErrorHandler(errHandler);
>
> String xmlToValidate = ...
> xmlReader.parse(xmlToValidate );
--------------030806050400000904000001
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Koloale,<br>
<br>
Given that the specification defines it like this:<br>
<br>
<div class="reprHeader"><span class="reprdef">XML Representation Summary</span>: <code >annotation</code> Element
Information Item</div>
<blockquote>
<p class="element-syntax-1"><a name="element-annotation"
id="element-annotation"><annotation</a><br>
id = <a
href=" http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#ID">ID</a><br>
<em>{any attributes with non-schema namespace . . .}</em>><br>
<em> Content: </em>(<a class="eltref"
href="http://www.w3.org/TR/xmlschema-1/#element-appinfo">appinfo</a> |
<a class="eltref"
href="http://www.w3.org/TR/xmlschema-1/#element-documentation">documentation</a>)*<br>
</annotation></p>
<p class="element-syntax"><a name="element-appinfo"
id="element-appinfo"><appinfo</a><br>
source = <a
href=" http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#anyURI">anyURI</a><br>
<em>{any attributes with non-schema namespace . . .}</em>><br>
<em> Content: </em>(<em>{any}</em>)*<br>
</appinfo></p>
<a name="element-documentation" id="element-documentation"><documentation</a><br>
source = <a
href=" http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#anyURI">anyURI</a><br>
xml:lang = <a
href=" http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#language">language</a><br>
<em>{any attributes with non-schema namespace . . .}</em>><br>
<em> Content: </em>(<em>{any}</em>)*<br>
</documentation><br>
</blockquote>
<p class="element-syntax">And that the schema for schemas has this:<br>
</p>
<p class="element-syntax"> <xs:element name="appinfo"
id="appinfo"><br>
<xs:annotation><br>
<xs:documentation
source=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/TR/xmlschema-1/#element-appinfo">"http://www.w3.org/TR/xmlschema-1/#element-appinfo"</a>/><br>
</xs:annotation><br>
<xs:complexType mixed="true"><br>
<xs:sequence minOccurs="0" maxOccurs="unbounded"><br>
<xs:any processContents="lax"/><br>
</xs:sequence><br>
<xs:attribute name="source" type="xs:anyURI"/><br>
<xs:anyAttribute namespace="##other" processContents="lax"/><br>
</xs:complexType><br>
</xs:element><br>
</p>
<p class="element-syntax">I'd say that validation error is bogus since
clearly an appinfo is allowed to have any attribute from any other
namespace.<br>
</p>
<p class="element-syntax">In other words, it sounds like a bug in the
JAXP implementation you're using.<br>
</p>
<br>
<br>
koloale wrote:
<blockquote cite="mid:go5t1m$c27$1@build.eclipse.org" type="cite">Hello,
Ed!
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">You could use ecore:type, but you'd have to
use ecore:ELongObject as the type, and unfortunately you'd have to
change the schema to import Ecore.xsd from location
platform:/plugins/org.eclipse.emf.ecore/model/Ecore.xsd.
<br>
</blockquote>
<br>
I get failure of source xsd validation when I use ecore extensions,
e.g. for <xsd:appinfo ecore:key="appinfo" source="teneo.jpa"> I
get: "Attribute 'ecore:key' cannot appear in element 'appinfo'"). Maybe
I need to set some special option in the validator. I use SAX parser
for validation like that:
<br>
// Create a JAXP SAXParserFactory and configure it
<br>
SAXParserFactory spf = SAXParserFactory.newInstance();
<br>
spf.setNamespaceAware(true);
<br>
spf.setValidating(true);
<br>
<br>
SAXParser saxParser = spf.newSAXParser();
<br>
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
<br>
saxParser.setProperty(JAXP_SCHEMA_SOURCE, xmlSchema);
<br>
<br>
XMLReader xmlReader = saxParser.getXMLReader();
<br>
xmlReader.setContentHandler(new DefaultHandler());
<br>
xmlReader.setErrorHandler(errHandler);
<br>
<br>
String xmlToValidate = ...
<br>
xmlReader.parse(xmlToValidate );
<br>
</blockquote>
</body>
</html>
--------------030806050400000904000001--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Fri Apr 26 00:51:09 GMT 2024
Powered by FUDForum. Page generated in 0.03233 seconds
|