|
|
|
Re: Serializing namespaces on the xsd schema level [message #231644 is a reply to message #231482] |
Wed, 20 May 2009 05:17 |
Eclipse User |
|
|
|
Originally posted by: valentinbaciu.hotmail.com
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.createFileU RI( "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_PREFI X);
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@gmail.com> wrote in message
news:1930c4413a09c2d4e2df4ba5467377a3$1@www.eclipse.org...
> 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.
>
|
|
|
|
Re: Serializing namespaces on the xsd schema level [message #231692 is a reply to message #231659] |
Wed, 20 May 2009 14:31 |
Eclipse User |
|
|
|
Originally posted by: valentinbaciu.hotmail.com
Yep, just add this line after setting the prefix for the WSDL namespace:
definition.addNamespace(SCHEMA_FOR_SCHEMA_PREFIX,
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
"Ravikanth " <ravikanth.somayaji@gmail.com> wrote in message
news:f993cef7c14c50671e824f859d18805e$1@www.eclipse.org...
> Hi Valentin,
>
> Thanks for your reply.
>
> I tried that and that works fine, but is there any way to serialize
> [xmlns:xsd="http://www.w3.org/2001/XMLSchema"] on both the root element
> and the xsd:schema element?
>
> Like, I said before, it is probably not the best of XML constructed, but
> it seems to be needed for some transformation I'm writing.
>
> -Ravi
>
> Valentin wrote:
>
>> Ravikanth, try this working example:
>
>> 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>
>
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03659 seconds