[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.webtools] Re: Serializing namespaces on the xsd schema level

Ravikanth, try this working example:

public class XSDSchemaPrefixSample extends TestCase
{

  private static final String SCHEMA_FOR_SCHEMA_PREFIX = "xsd"; 
//$NON-NLS-1$

  public void testSupportsSchemaPrefix() throws Exception
  {
    ResourceSetImpl resourceSet = new ResourceSetImpl();
    WSDLResourceImpl wsdlResource = 
(WSDLResourceImpl)resourceSet.createResource(URI.createFileURI("schemaTest.wsdl"));

    WSDLFactory factory = WSDLFactory.eINSTANCE;
    Definition definition = factory.createDefinition();
    wsdlResource.getContents().add(definition);
    definition.setTargetNamespace("http://www.example.org";);
    definition.addNamespace("wsdl", WSDLConstants.WSDL_NAMESPACE_URI);

    Types types = factory.createTypes();
    definition.setTypes(types);

    XSDSchemaExtensibilityElement schemaExtensibilityElement = 
factory.createXSDSchemaExtensibilityElement();
    types.addExtensibilityElement(schemaExtensibilityElement);

    XSDFactory xsdFactory = XSDFactory.eINSTANCE;
    XSDSchema schema = xsdFactory.createXSDSchema();
    schemaExtensibilityElement.setSchema(schema);
    Map<String, String> qNamePrefixToNamespaceMap = 
schema.getQNamePrefixToNamespaceMap();
    qNamePrefixToNamespaceMap.put(SCHEMA_FOR_SCHEMA_PREFIX, 
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
    schema.setSchemaForSchemaQNamePrefix(SCHEMA_FOR_SCHEMA_PREFIX);

    wsdlResource.save(null);
  }
}

The code above produces a WSDL document that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"; 
targetNamespace="http://www.example.org";>
  <wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
  </wsdl:types>
</wsdl:definitions>

"Ravikanth " <ravikanth.somayaji@xxxxxxxxx> wrote in message 
news:1930c4413a09c2d4e2df4ba5467377a3$1@xxxxxxxxxxxxxxxxxx
> Thanks for the reply. I did try that, but it doesn't seem to serialize. It 
> must be an XMLSerializer thing that restricts child elements to have 
> namespaces declared if it has already been declared for the parent 
> element.
>