namespace duplicate issue in xml

1.9k views Asked by At

I am encountering a namespace duplicate issue in the response xml of my webservice. I have a responder.xsd that uses customer.xsd and common.xsd My response xml is structured using the elements in these two xsds. A sample XML response is as below:

...
<ns:RoleType></ns:RoleType>
<ns:Addresses>
  <ns:PostalInfo>
    <comm:AddressLine></comm:AddressLine>
    <comm:City></comm:City>
  </ns:PostalInfo>
</ns:Addresses>
<ns:ValidFlag></ns:ValidFlag>
...

where ns: is the customer namespace and comm: is the common namespace.

But the response that I get is as below

...
<ns1:RoleType xmlns:ns1="urn:Customer:domain:5"></ns1:RoleType>
<ns2:Addresses xmlns:ns2="urn:Customer:domain:5">
  <ns2:PostalInfo>
    <ns3:AddrLine xmlns:ns3="urn:Common:domain:5"></ns3:AddrLine>
    <ns4:City xmlns:ns4="urn:Common:domain:5"></ns4:City>
  </ns2:PostalInfo>
</ns2:Addresses>
<ns5:ValidFlag xmlns:ns3="urn:Customer:domain:5></ns5:ValidFlag>
...

Can someone help me understand why the same namespace is duplicating with incremental numbers like ns1,ns2 and comm1,comm2 etc? How can I fix this?

Updated: Code snippet that is well formed and with the root element.

<GetHCPResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:services:ServiceResponder:5" xsi:schemaLocation="urn:services:ServiceResponder:5 C:\Users\vijay\Desktop\wsdl\wsdl\Service_5_2\ServiceResponder.xsd">
        <StatusCode>0</StatusCode>
        <StatusMessage>Success</StatusMessage>
        <HCP>
            <ns1:ID xmlns:ns1="urn:Customer:domain:5">29199486</ns1:ID>
            <ns2:CustomerClass xmlns:ns2="urn:Customer:domain:5">HCP</ns2:CustomerClass>
            <ns3:CustomerStatus xmlns:ns3="urn:Customer:domain:5">A</ns3:CustomerStatus>
            <ns4:RoleType xmlns:ns4="urn:Customer:domain:5">P</ns4:RoleType>
            <ns5:Addresses xmlns:ns5="urn:Customer:domain:5">
                <ns5:PostalContact>
                    <ns5:MasterAddressID>15863814</ns5:MasterAddressID>
                    <ns5:PostalInfo>
                        <ns6:AddressLine LineNo="1" xmlns:ns6="urn:CommonTypes:domain:5">8252 NW 25TH ST</ns6:AddressLine>
                        <ns7:City xmlns:ns7="urn:CommonTypes:domain:5">DORAL</ns7:City>

...

Thanks, Vijay

2

There are 2 answers

1
Wanderley On

It seems that you are consuming a 3rd party web service and you dont want to modifiy the xsds and wsdls, right?

But as you said that its the same namespace...did you tried to update manually xsd and wsdl before consuming, unifying namespaces?

5
kjhughes On

Namespace prefixes matter only because of the namespace URI to which they're bound. The actual value of a namespace prefix is otherwise insignificant.