XSDEnumeration question [message #68840] |
Tue, 25 July 2006 10:35 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 |
Ed Merks Messages: 33264 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04297 seconds