Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » XSDEnumeration question
XSDEnumeration question [message #68840] Tue, 25 July 2006 10:35 Go to next message
Eclipse UserFriend
Originally posted by: ashish.deshpande.cc

Hello everyone,
I am having some trouble with enumeration facets. Here's my code snippet:

public void testEnumerationSchema () throws Exception {
XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
schema.setSchemaForSchemaQNamePrefix("xsd");
schema.getQNamePrefixToNamespaceMap().put(schema.getSchemaFo rSchemaQNamePrefix(),
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

// Create element
XSDElementDeclaration xsdEl =
XSDFactory.eINSTANCE.createXSDElementDeclaration();
xsdEl.setName("foo");
// Create an enumeration simple type.
XSDSimpleTypeDefinition definition =
XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();

definition.setBaseTypeDefinition(schema.getSchemaForSchema() .resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_ URI_2001,
"string"));
XSDEnumerationFacet facet =
XSDFactory.eINSTANCE.createXSDEnumerationFacet();
facet.setLexicalValue("abc");
definition.getFacetContents().add(facet);
// Add simple type to element
xsdEl.setTypeDefinition(definition);
// Add element to the schema.
schema.getContents().add(xsdEl);

// Print using XSDResourceSet
printSchemaToOutputStream(schema, System.out);
}

This produces the following output:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="foo" type="null"/>
</xsd:schema>

As you can see, there is no enumeration. I have searched this newsgroup
but couldn't find an answer. What am I doing wrong?

Thanks for your help.
-Ashish
Re: XSDEnumeration question [message #68862 is a reply to message #68840] Tue, 25 July 2006 12:13 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Ashish,

You didn't add the enumeration's definition to any containment
reference. Since you didn't give it a name and didn't add it to the
schema, I assume you intent it to be an anonymous type definition for
the element. Try xsdEl.setAnonymousTypeDefinition(definition).

Ashish Deshpande wrote:
> Hello everyone,
> I am having some trouble with enumeration facets. Here's my code snippet:
>
> public void testEnumerationSchema () throws Exception {
> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
> schema.setSchemaForSchemaQNamePrefix("xsd");
> schema.getQNamePrefixToNamespaceMap().put(schema.getSchemaFo rSchemaQNamePrefix(),
> XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
>
> // Create element
> XSDElementDeclaration xsdEl =
> XSDFactory.eINSTANCE.createXSDElementDeclaration();
> xsdEl.setName("foo");
> // Create an enumeration simple type.
> XSDSimpleTypeDefinition definition =
> XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
>
> definition.setBaseTypeDefinition(schema.getSchemaForSchema() .resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_ URI_2001,
> "string"));
> XSDEnumerationFacet facet =
> XSDFactory.eINSTANCE.createXSDEnumerationFacet();
> facet.setLexicalValue("abc");
> definition.getFacetContents().add(facet);
> // Add simple type to element
> xsdEl.setTypeDefinition(definition);
> // Add element to the schema.
> schema.getContents().add(xsdEl);
>
> // Print using XSDResourceSet
> printSchemaToOutputStream(schema, System.out);
> }
>
> This produces the following output:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:element name="foo" type="null"/>
> </xsd:schema>
>
> As you can see, there is no enumeration. I have searched this
> newsgroup but couldn't find an answer. What am I doing wrong?
>
> Thanks for your help.
> -Ashish
Re: XSDEnumeration question [message #598442 is a reply to message #68840] Tue, 25 July 2006 12:13 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26285
Registered: July 2009
Senior Member
Ashish,

You didn't add the enumeration's definition to any containment
reference. Since you didn't give it a name and didn't add it to the
schema, I assume you intent it to be an anonymous type definition for
the element. Try xsdEl.setAnonymousTypeDefinition(definition).

Ashish Deshpande wrote:
> Hello everyone,
> I am having some trouble with enumeration facets. Here's my code snippet:
>
> public void testEnumerationSchema () throws Exception {
> XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
> schema.setSchemaForSchemaQNamePrefix("xsd");
> schema.getQNamePrefixToNamespaceMap().put(schema.getSchemaFo rSchemaQNamePrefix(),
> XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
>
> // Create element
> XSDElementDeclaration xsdEl =
> XSDFactory.eINSTANCE.createXSDElementDeclaration();
> xsdEl.setName("foo");
> // Create an enumeration simple type.
> XSDSimpleTypeDefinition definition =
> XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
>
> definition.setBaseTypeDefinition(schema.getSchemaForSchema() .resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_ URI_2001,
> "string"));
> XSDEnumerationFacet facet =
> XSDFactory.eINSTANCE.createXSDEnumerationFacet();
> facet.setLexicalValue("abc");
> definition.getFacetContents().add(facet);
> // Add simple type to element
> xsdEl.setTypeDefinition(definition);
> // Add element to the schema.
> schema.getContents().add(xsdEl);
>
> // Print using XSDResourceSet
> printSchemaToOutputStream(schema, System.out);
> }
>
> This produces the following output:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:element name="foo" type="null"/>
> </xsd:schema>
>
> As you can see, there is no enumeration. I have searched this
> newsgroup but couldn't find an answer. What am I doing wrong?
>
> Thanks for your help.
> -Ashish
Previous Topic:XSDEnumeration question
Next Topic:how to create a xml schema for ecore metamodel
Goto Forum:
  


Current Time: Sun Dec 21 04:45:54 GMT 2014

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

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