Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are these two XML`s the same?

i am currently writing a web service client in delphi 7 (service itself is in c#). everything seems to be working just fine. when i run a fiddler to look how does the xml going from my client app looks like i noticed that is looks different when i write the "same" client app in c#. Below are two xml`s

one that goes from a Delphi 7 app

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS2="http://tempuri.org/">
    <NS1:SomeTagName xmlns:NS1="http://tempuri.org/">
      <SomeID xsi:type="xsd:int">12345</SomeID>
      <SomeStatus xsi:type="NS2:SomeStatusType">SOME_OK_STATUS</SomeStatus>
    </NS1:SomeTagName>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

one that goes from c# app

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <SomeTagName xmlns="http://tempuri.org/">
      <SomeID>12345</SomeID>
      <SomeStatus>SOME_OK_STATUS</SomeStatus>
    </SomeTagName>
  </s:Body>
</s:Envelope>

i am not fluent in xml so i did some research and to this moment i am able to tell that

  1. UTF-8 is the default for documents without encoding information - ref. here - that means no difference here
  2. XML Namespaces provide a method to avoid element name conflicts - ref. here - namespaces are different (s: and SOAP-ENV:) but there are specified, and as far as i am concerned should not make the difference either

but what about the schema - not sure about that. There are some extra attributes in the Envelope or datatypes in SomeID and SomeStatus tags. But that came from service wsdl (i quess?!).

Final questions:

  1. Why the app written in c# (vs2012) does not add all the extra schema information to the xml. Does it really matter if the xml has them or not?
  2. can anyone tell if these can be considered as the same?
like image 568
Surrogate Avatar asked Dec 29 '14 12:12

Surrogate


1 Answers

As for your second final question: these XML files can not be considered the same. Here's why:

  1. The namespaces for the elements SomeID and SomeStatus are not the same. In the Delphi XML, no default namespace is ever specified anywhere in the XML. We only see the following namespaces:

    • xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    • xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    • xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    • xmlns:NS2="http://tempuri.org/"
    • xmlns:NS1="http://tempuri.org/"

    Thus, the elements SomeID and SomeStatus are not in any namespace as they lack a namespace prefix.

    Conversely, the XML from the c# app has the following namespaces

    • xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    • xmlns="http://tempuri.org/"

    As you can see, the second xmlns attribute is a default namespace attribute, so the child elements SomeID and SomeStatus are in the "http://tempuri.org/" namespace. This means that these elements have different qualified names and are thus not equivalent.

    (If I had to guess, I would reckon that the c# XML is correct and the Delphi XML has a bug. But I have no way to tell since the XSD for the SOAP standard to which you refer has no particular schema for the Body.)

  2. The Delphi XML has additional information about the type of SomeID and SOME_OK_STATUS. This may be useful to receivers since the SOAP standard "mandates no particular structure or interpretation of these elements, and provides no standard means for specifying the processing to be done" for elements inside the Body. However, if the receiver already knows what to expect in these elements, these attributes may be unnecessary.

These are the main logical differences between the XML samples that I see.

As for the first final question, we would need to see the c# code to comment definitively on why the XML it produces looks like that. If XmlSerializer was used for serialization, it will not output xsi:type information for non-polymorphic fields unless forced to do so

like image 158
dbc Avatar answered Sep 23 '22 23:09

dbc