|
Re: Default Values of simpleContent [message #643402 is a reply to message #643366] |
Mon, 06 December 2010 18:09 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
Rob,
This looks to be one of those horrible cases that just doesn't map
well. Complex types map to EClasses, features with an EClass as their
type must be an EReference, and an EReference doesn't support a default
value. In the end, the "value" feature of NewType in Ecore needs to
specify a default, but there's no way to specify that in the schema and
there's no way for it to be different depending on where it's used so
that doesn't solve the problem either. Even the difference between
<default:elementWithDefault
xmlns:default="http://example.com/ElementSimpleDefault"
NewAttribute="attrib"
NewAttribute1="attrib1"/>
and
<default:elementWithDefault
xmlns:default="http://example.com/ElementSimpleDefault"
NewAttribute="attrib"
NewAttribute1="attrib1"></default:elementWithDefault
is very subtle. Is the former correct and the latter incorrect? If
it's correct, does that make it impossible to specify an empty string
when there is a default?
I'm not sure this problem is fixable...
Rob wrote:
> Hi, I've been looking at an issue involving default values, if I have
> a schema:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:tns="http://example.com/ElementSimpleDefault"
> targetNamespace="http://example.com/ElementSimpleDefault">
> <xsd:element name="elementWithDefault" type="tns:NewType"
> default="10"/>
> <xsd:complexType name="NewType">
> <xsd:simpleContent>
> <xsd:extension base="xsd:integer">
> <xsd:attribute name="NewAttribute" type="xsd:string"/>
> <xsd:attribute name="NewAttribute1" type="xsd:string"/>
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>
> </xsd:schema>
>
> And then get it to load the following XML:
>
> <default:elementWithDefault
> xmlns:default="http://example.com/ElementSimpleDefault"
> NewAttribute="attrib"
> NewAttribute1="attrib1"/>
>
> Then it will fail with the exception:
>
> org.eclipse.emf.ecore.xmi.IllegalValueException: Value '' is not legal.
>
> This seems to be caused by the fact that the default value of "10" is
> not being used when it is not specified in any input XML.
>
> Is this a know issue - or am I doing something wrong some-where?
>
> Thanks
>
> Rob
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03246 seconds