|
Re: Notation validation failing valid data [message #629795 is a reply to message #629748] |
Wed, 29 September 2010 14:58 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------080704020208090301070704
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Rob,
Comments below.
Rob wrote:
> Hi, I've hit a problem that I am hoping some-one can shed some light
> on for me. I have the following schema:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="http://example.com/Notation"
> targetNamespace="http://example.com/Notation">
> <xs:notation name="gif" public="image/gif" system="view.exe"/>
> <xs:notation name="jpeg" public="image/jpeg" system="view.exe"/>
> <xs:element name="image">
> <xs:complexType>
> <xs:attribute name="type">
> <xs:simpleType>
> <xs:restriction base="xs:NOTATION">
> <xs:enumeration value="gif"/>
> <xs:enumeration value="jpeg"/>
> </xs:restriction>
> </xs:simpleType>
> </xs:attribute>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
>
> I can generate the EMF classes OK, and can construct and populate in
> code:
>
> ImageType createImageType = NotationFactory.eINSTANCE.createImageType();
> QName name = new QName("gif");
> createImageType.setType(name);
>
>
> This can be saved and loaded as much as I like, giving XML as follows:
>
> <notation:image xmlns:notation="http://example.com/Notation" type="gif"/>
>
>
> However as soon as I try and validate it
>
> Diagnostician.INSTANCE.validate(createImageType);
>
> It will give me an error along the following lines:
>
> The feature 'type' of
> 'com.example.notation.impl.ImageTypeImpl@16546ef{#//@image}' contains
> a bad value [The value 'gif' must be one of {'gif', 'jpeg'}
>
> However it is of type=gif, so I'm not really sure what is going on
I think it should be
QName name = new QName("http://example.com/Notation", "gif");
>
> Thanks, Rob
--------------080704020208090301070704
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">
Rob,<br>
<br>
Comments below.<br>
<br>
<br>
Rob wrote:
<blockquote cite="mid:i7vdgs$10p$1@news.eclipse.org" type="cite">Hi,
I've hit a problem that I am hoping some-one can shed some light on
for me. I have the following schema:
<br>
<br>
<xs:schema xmlns:xs=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://example.com/Notation">"http://example.com/Notation"</a>
targetNamespace=<a class="moz-txt-link-rfc2396E" href="http://example.com/Notation">"http://example.com/Notation"</a>>
<br>
<xs:notation name="gif" public="image/gif" system="view.exe"/>
<br>
<xs:notation name="jpeg" public="image/jpeg"
system="view.exe"/>
<br>
<xs:element name="image">
<br>
<xs:complexType>
<br>
<xs:attribute name="type">
<br>
<xs:simpleType>
<br>
<xs:restriction base="xs:NOTATION">
<br>
<xs:enumeration value="gif"/>
<br>
<xs:enumeration value="jpeg"/>
<br>
</xs:restriction>
<br>
</xs:simpleType>
<br>
</xs:attribute>
<br>
</xs:complexType>
<br>
</xs:element>
<br>
</xs:schema>
<br>
<br>
<br>
I can generate the EMF classes OK, and can construct and populate in
code:
<br>
<br>
ImageType createImageType =
NotationFactory.eINSTANCE.createImageType();
<br>
QName name = new QName("gif");
<br>
createImageType.setType(name);
<br>
<br>
<br>
This can be saved and loaded as much as I like, giving XML as follows:
<br>
<br>
<notation:image xmlns:notation=<a class="moz-txt-link-rfc2396E" href="http://example.com/Notation">"http://example.com/Notation"</a>
type="gif"/>
<br>
<br>
<br>
However as soon as I try and validate it
<br>
<br>
Diagnostician.INSTANCE.validate(createImageType);
<br>
<br>
It will give me an error along the following lines:
<br>
<br>
The feature 'type' of
'com.example.notation.impl.ImageTypeImpl@16546ef{#//@image}' contains a
bad value [The value 'gif' must be one of {'gif', 'jpeg'}
<br>
<br>
However it is of type=gif, so I'm not really sure what is going on
<br>
</blockquote>
I think it should be<br>
<blockquote>QName name = new QName(<a class="moz-txt-link-rfc2396E" href="http://example.com/Notation">"http://example.com/Notation"</a>,
"gif");<br>
</blockquote>
<blockquote cite="mid:i7vdgs$10p$1@news.eclipse.org" type="cite"><br>
Thanks, Rob
<br>
</blockquote>
</body>
</html>
--------------080704020208090301070704--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Notation validation failing valid data [message #629827 is a reply to message #629818] |
Wed, 29 September 2010 16:11 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Rob,
Comments below.
Rob wrote:
> Hi Ed,
>
> Thanks again for the super-quick reply. If I make the changes that
> you suggest and supply the namespace URI it will indeed work.
>
> However if I was just to start with some XML, say:
>
> <notation:image xmlns:notation="http://example.com/Notation" type="gif"/>
Shouldn't this be type="notation:gif"?
>
>
> As detailed in the following example:
>
> http://www.w3schools.com/Schema/el_notation.asp
In there they show
<image type="gif"></image>
but they don't show the xmlns declaration that's needed to conform to
the schema. I think it should be
<image xmlns="http://example.com/Notation" type="gif"></image>
and I thin kin that case, the QName value for "gif" is implicitly
qualified with the namespace for Notation as opposed to the explicit
qualification I showed up above.
>
> Run a load on it to create the EMF representation, and then do a
> validate, I still get the error.
>
> This would then lead me to a situation where I load in valid XML for
> the schema, but can then not validate the EMF that is generated.
Not really. Despite assertions about XML being simple, the handling of
namespace qualification seems to be one of those things that few people
understand well...
>
> I would appreciate any further help you can supply on this.
>
> Thanks, Rob
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.04596 seconds