|
Re: [xsd2ecore] defaultValueLiteral issue with required strings [message #1039393 is a reply to message #1039109] |
Fri, 12 April 2013 05:44 |
Ed Merks Messages: 33107 Registered: July 2009 |
Senior Member |
|
|
David,
Comments below.
On 11/04/2013 9:26 PM, David Rees wrote:
> We are running into a problem with xsd2ecore and defaultValueLiteral
> for xs:strings.
>
> Given the following XSD:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
> <xs:element name="ROOT">
> <xs:complexType>
> <xs:sequence>
> <xs:element maxOccurs="unbounded" name="SUB">
> <xs:complexType>
> <xs:sequence>
> <xs:element maxOccurs="1" minOccurs="1"
> type="xs:string" name="STRING"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
>
> If we create a SUB, but don't explicitly set the STRING and save the
> model we get the following which is actually invalid, because STRING
> is required (minOccurs of 1).
>
>
> <ROOT xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="emptyStringTest.xsd">
> <SUB/>
> </ROOT>
>
>
> The problem seems to be that the defaultValueLiteral for STRING is
> null rather than an empty string.
You didn't specify empty string anywhere right?
> Using OPTION_KEEP_DEFAULT_CONTENT when saving doesn't help since it
> explicitly doesn't apply to null values.
That's right.
>
> My question is if this is something that Xsd2Ecore can handle since it
> knows that STRING is minOccurs=1 and therefore can't be null?
It would need to know what the value should be and if some default value
were sufficient, the schema could specify that default rather than
specify that a value must be provided in each instance.
>
> Perhaps it can't automatically handle it because it can't assume the
> defaultLiteralValue is the empty string.
No, types that allow null have null has their default value, so that
only leaves primitives with their zero values...
> In that case, is there a way for us to indicate a global
> defaultLiteralValue for xs:string? Or do we have to explicitly walk
> the model and set defaultLiteralValue to the empty string?
>
> I'll add that adding ecore:default="" in the original XSD itself is
> not an option for us because we don't own the XSD. Of course we add it
> in our own modified XSD, but its easier to do that against the
> Xsd2Ecore generated metamodel.
That's the only way.
>
> Thanks,
> dave
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.01374 seconds