Please consider those two equivalent xml documents generated as a response to a SOAP call.
Document one:
<?xml version="1.0" encoding="utf-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<ns2:ServerVersionInfo xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types" MajorVersion="15" MinorVersion="1" MajorBuildNumber="845" MinorBuildNumber="34"/>
</S:Header>
<S:Body>
<ns3:GetUserAvailabilityResponse xmlns:ns3="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types">
<ns3:FreeBusyResponseArray>
<ns3:FreeBusyResponse>
<ns3:ResponseMessage ResponseClass="Success">
<ns3:ResponseCode>NoError</ns3:ResponseCode>
</ns3:ResponseMessage>
<ns3:FreeBusyView>
<ns2:FreeBusyViewType>MergedOnly</ns2:FreeBusyViewType>
<ns2:MergedFreeBusy>0000</ns2:MergedFreeBusy>
</ns3:FreeBusyView>
</ns3:FreeBusyResponse>
</ns3:FreeBusyResponseArray>
</ns3:GetUserAvailabilityResponse>
</S:Body>
</S:Envelope>
Document two:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MajorVersion="15" MinorVersion="1" MajorBuildNumber="845" MinorBuildNumber="34"/>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetUserAvailabilityResponse xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<FreeBusyResponseArray>
<FreeBusyResponse>
<ResponseMessage ResponseClass="Success">
<ResponseCode>NoError</ResponseCode>
</ResponseMessage>
<FreeBusyView>
<FreeBusyViewType xmlns="http://schemas.microsoft.com/exchange/services/2006/types">MergedOnly</FreeBusyViewType>
<MergedFreeBusy xmlns="http://schemas.microsoft.com/exchange/services/2006/types">0000</MergedFreeBusy>
</FreeBusyView>
</FreeBusyResponse>
</FreeBusyResponseArray>
</GetUserAvailabilityResponse>
</s:Body>
</s:Envelope>
Correct me if I am wrong but those DOMs look semantically similar except the xml namespace declaration styles. I would like to tweak the jax-ws output from my java application from the style of document one the style of document two.
I am Ok with re-processing the DOM with a javax.xml.transform.Transformer
if necessary.
You could do it in XSLT like this:
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="bindings">
<ns prefix="s:" uri="http://schemas.xmlsoap.org/soap/envelope/"/>
<ns prefix="h:" uri="http://schemas.microsoft.com/exchange/services/2006/types"/>
<ns prefix="" uri="http://schemas.microsoft.com/exchange/services/2006/messages"/>
</xsl:variable>
<xsl:template match="*">
<xsl:variable name="p" select="$bindings/ns[@uri=namespace-uri(current())]/@prefix"/>
<xsl:element name="{$p}{local-name()}" namespace="{namespace-uri()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:transform>
Now tested (though not with xsltproc).
It gives the output from your "Document two" except that FreeBusyViewType and MergedFreeBusy use the namespace prefix "h" rather than being unprefixed in the default namespace. You would need some further tweaks to change that, since my code generates a document in which all elements in a given namespace have the same prefix. I've no idea why you should want your output in preference. (In fact, to be honest, I have no idea what the point of this little exercise is. Why would anyone care?)