Part of my project involves heavy transformations of user-defined schema documents. I need to be able to change target namespaces, support type cross-references and build wsdl
upon multiple schema documents.One of the most commonly used operations is changing namespace prefix prior to importing schema into wsdl file. I'm using org.xml.sax.ContentHandler
and it's startPrefixMapping
method to handle namespaces. All works fine and flawless unless I want to change element types.
Here is simple schema fragment
<schema xmlns="http://www.w3.org/2001/XMLSchema"><complexType name="Param"><sequence><element name="key" type="string"/><element name="value" type="string"/></sequence></complexType><!-- omitted -->
which must be placed inside wsdl as follows:
<definitions xmlns:xs="http://www.w3.org/2001/XMLSchema"><types><xs:schema><xs:complexType name="Param"><xs:sequence><xs:element name="key" type="xs:string"/> <!-- 'xs:' to be added --><xs:element name="value" type="xs:string"/> <!-- 'xs:' to be added --></xs:sequence></xs:complexType><!-- omitted -->
The problem is that some schema's attribute values (type
in <element>
, base
in <extension>
) are namespace-aware and are subject to change in the above example. As I can see, neither DOM, nor SAX parsers are able to handle this situation so I'm currently using ugly string operations to retrieve namespace info from particular attribute values.
Am I missing somethiing? Are there any api's, libraries or other schema-specific tools to handle such sort of tasks?