Skip to main content



      Home
Home » Archived » XML Schema Definition (XSD) » showing the prefix
showing the prefix [message #57003] Wed, 12 January 2005 12:31 Go to next message
Eclipse UserFriend
Originally posted by: ooi.de.ibm.com

Hello,

I would like to know how do we "show" the prefixes in the schema we
generate.. for eg.

<xsd:import....> instead of <import>
<xsd:element ..> instead of <element>

thank you.
Re: showing the prefix [message #57057 is a reply to message #57003] Thu, 13 January 2005 12:06 Go to previous message
Eclipse UserFriend
HT Ooi wrote:
> I would like to know how do we "show" the prefixes in the schema we
> generate.. for eg.
> <xsd:import....> instead of <import>
> <xsd:element ..> instead of <element>

You can set the qname prefix used to reference the schema for schema
namespace via XSDSchema.setSchemaForSchemaQNamePrefix(). There's also a
map accesible via XSDSchema.getQNamePrefixToNamespaceMap() that defines
all of the namespace qname-namespace pairs to use in the schema. It must
have an entry that agrees with the above schema for schema namespace
prefix, too. So, for the result shown in your example:

XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();

schema.setTargetNamespace("http://www.example.com/test");
schema.setSchemaForSchemaQNamePrefix("xsd");

Map namespaceMap = schema.getQNamePrefixToNamespaceMap();
namespaceMap.put(schema.getSchemaForSchemaQNamePrefix(),
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

You'd also want to set a prefix to use for the target namespace. Setting
null makes it the default namespace.

namespaceMap.put(null, schema.getTargetNamespace());

Cheers,
Dave
Re: showing the prefix [message #593566 is a reply to message #57003] Thu, 13 January 2005 12:06 Go to previous message
Eclipse UserFriend
HT Ooi wrote:
> I would like to know how do we "show" the prefixes in the schema we
> generate.. for eg.
> <xsd:import....> instead of <import>
> <xsd:element ..> instead of <element>

You can set the qname prefix used to reference the schema for schema
namespace via XSDSchema.setSchemaForSchemaQNamePrefix(). There's also a
map accesible via XSDSchema.getQNamePrefixToNamespaceMap() that defines
all of the namespace qname-namespace pairs to use in the schema. It must
have an entry that agrees with the above schema for schema namespace
prefix, too. So, for the result shown in your example:

XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();

schema.setTargetNamespace("http://www.example.com/test");
schema.setSchemaForSchemaQNamePrefix("xsd");

Map namespaceMap = schema.getQNamePrefixToNamespaceMap();
namespaceMap.put(schema.getSchemaForSchemaQNamePrefix(),
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

You'd also want to set a prefix to use for the target namespace. Setting
null makes it the default namespace.

namespaceMap.put(null, schema.getTargetNamespace());

Cheers,
Dave
Previous Topic:complexContent
Next Topic:complexContent
Goto Forum:
  


Current Time: Thu May 08 03:51:04 EDT 2025

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

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

Back to the top