Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [xsd2ecore] defaultValueLiteral issue with required strings
[xsd2ecore] defaultValueLiteral issue with required strings [message #1039109] Thu, 11 April 2013 19:26 Go to next message
David Rees is currently offline David ReesFriend
Messages: 47
Registered: September 2012
Member
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. Using OPTION_KEEP_DEFAULT_CONTENT when saving doesn't help since it explicitly doesn't apply to null values.

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?

Perhaps it can't automatically handle it because it can't assume the defaultLiteralValue is the empty string. 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.

Thanks,
dave

Re: [xsd2ecore] defaultValueLiteral issue with required strings [message #1039393 is a reply to message #1039109] Fri, 12 April 2013 05:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
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/
Re: [xsd2ecore] defaultValueLiteral issue with required strings [message #1039757 is a reply to message #1039393] Fri, 12 April 2013 14:43 Go to previous message
David Rees is currently offline David ReesFriend
Messages: 47
Registered: September 2012
Member
Ok, that is what we were expecting. Thanks!
Previous Topic:XMI Serialization with ns-prefix
Next Topic:getHREF of org.eclipse.emf.ecore.xmi.XMLHelper doesn't encode '&' in element name
Goto Forum:
  


Current Time: Tue Mar 19 04:03:18 GMT 2024

Powered by FUDForum. Page generated in 0.01374 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top