Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » How to create a local simpleContentComplexType ?
How to create a local simpleContentComplexType ? [message #572541] Thu, 29 May 2003 16:03
Eclipse UserFriend
Originally posted by: dirk.schesmer.divos.de

Hi there, I try to create a simpleContentComplexType being local to an
global element called title.

As a result, I always get an additional namespace prefix "Q1". I do not get
this "Q1" prefix when I create a global type titleType having the same
structure and associating it then to an element title (see version 1 and 2
in the code).

Can please anyone give me a clue how come? I attached the code below!

Thanks for help,

Dirk V. Schesmer





public XSDSchema initSimpleContentComplexTypeDefinition() throws Exception {

XSDFactory xsdFactory;

XSDSchema xsdSchema;

Map qNamePrefixToNamespaceMap;

XSDElementDeclaration elementDecl;

xsdFactory = XSDFactory.eINSTANCE;

xsdSchema = xsdFactory.createXSDSchema();

xsdSchema.setTargetNamespace("http://dyomedea.com/ns/library");

xsdSchema.setElementFormDefault(XSDForm.QUALIFIED_LITERAL);

xsdSchema.setAttributeFormDefault(XSDForm.QUALIFIED_LITERAL) ;

xsdSchema.setSchemaForSchemaQNamePrefix("xsd");

qNamePrefixToNamespaceMap = xsdSchema.getQNamePrefixToNamespaceMap();

qNamePrefixToNamespaceMap

..put(xsdSchema.getSchemaForSchemaQNamePrefix(), XSDConstants /*}*/

..SCHEMA_FOR_SCHEMA_URI_2001);

String targetNamespace = xsdSchema.getTargetNamespace();

qNamePrefixToNamespaceMap.put("lib", targetNamespace);

qNamePrefixToNamespaceMap.put(

xsdSchema.getSchemaForSchemaQNamePrefix(),

XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

qNamePrefixToNamespaceMap.put(null, "http://dyomedea.com/ns/library");

elementDecl =

xsdSchema.resolveElementDeclaration(targetNamespace, "title");

XSDComplexTypeDefinition simpleContentComplexTypeDefinition =

xsdFactory.createXSDComplexTypeDefinition();


simpleContentComplexTypeDefinition.setDerivationMethod(

XSDDerivationMethod.EXTENSION_LITERAL);

XSDSimpleTypeDefinition baseTypeString =

xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition(

"string");

simpleContentComplexTypeDefinition.setBaseTypeDefinition(

baseTypeString);

XSDSimpleTypeDefinition anonymousSimpleTypeDefinition =

xsdFactory.createXSDSimpleTypeDefinition();

simpleContentComplexTypeDefinition.setContent(

anonymousSimpleTypeDefinition);

XSDAttributeDeclaration simpleAttributeDeclaration =

xsdFactory.createXSDAttributeDeclaration();

simpleAttributeDeclaration.setName("bookId");

simpleAttributeDeclaration.setTypeDefinition(baseTypeString) ;

XSDAttributeUse simpleAttributeUse = xsdFactory.createXSDAttributeUse();

simpleAttributeUse.setContent(simpleAttributeDeclaration);

simpleContentComplexTypeDefinition.getAttributeContents().ad d(

simpleAttributeUse);

// version 1:

// create simpleContentComplexType as global type used by "title" element

simpleContentComplexTypeDefinition.setName("titleType");

xsdSchema.getContents().add(simpleContentComplexTypeDefiniti on);

elementDecl.setTypeDefinition(simpleContentComplexTypeDefini tion);

// version 2:

// attempt to create simpleContentComplexType as "title" element's local
type

// => a new namespace prefix "Q1" I have no clue where it comes from ?!

//elementDecl.setAnonymousTypeDefinition(simpleContentComple xTypeDefinition)
;

//xsdSchema.getContents().add(elementDecl);

xsdSchema.getContents().add(elementDecl);

//--------------------------------------------

xsdSchema.updateElement();

return xsdSchema;

}
Previous Topic:xs:include and xs:import
Next Topic:Probs with "Shane Curcuru's Article"
Goto Forum:
  


Current Time: Tue Apr 23 17:03:22 GMT 2024

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

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

Back to the top