Author |
Message
|
akkypaul |
Posted: Mon Jun 22, 2020 12:11 pm Post subject: Space Character not showing up in Response XML |
|
|
 Apprentice
Joined: 30 Jun 2014 Posts: 44 Location: India
|
I am trying to create an XML response which with one of the fields which has be has the values of SAPCE [' '].
I have kept the encoding as 546 and the ccsid as 1208.
The simple assignment statement does assign a space character to response which I can see while debugging.
However, when I see the response in ReadyAPI's output, I don't see the space character.
Code: |
SET OutputRoot.SOAP.Body.SomeField.Somefield = ' '; |
Actual Output:
Code: |
<Somefield></Somefield> |
Required Output:
Code: |
<Somefield> </Somefield> |
Can someone please tell me what am I missing here?
 |
|
Back to top |
|
 |
Vitor |
Posted: Mon Jun 22, 2020 12:34 pm Post subject: Re: Space Character not showing up in Response XML |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
akkypaul wrote: |
Can someone please tell me what am I missing here? |
Potentially nothing.
Upfront let me be clear: I don't know "ReadyAPI", never used it, never heard of it.
Firstly are you sure that the space you're adding isn't being parsed out by the ReadyAPI tool? Whitespace can be handled in a number of different ways and it's highly likely that this tool is considering the whitespace to be irrelevant content & removing it.
Secondly, and on the same line, are you sure you want a space? There's a difference between these:
Code: |
<Somefield> </Somefield>
<Somefield></Somefield>
<Somefield/>
|
Even though a lot of people use them interchangeably, parsers do not.
I would put a bet down (especially as you claim to be able to see the space while debugging) that it's getting removed somewhere in the serialization/deserialization/parsing space and I'd double down on parsing.
Take a user trace (which is not the same as using the debugger) to confirm that you're getting the space in the message tree. Then use something like Wireshark to see what's actually being delivered over the wire to this ReadyAPI tool. As I said, I bet what's getting delivered has a space there. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
gbaddeley |
Posted: Mon Jun 22, 2020 3:41 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
You may be missing an understanding of "whitespace" in the XML element content space. Adding spaces may cause ambiguities with some parsers, and many will ignore or compact spaces unless they are told otherwise. Do a search for the reserved attribute "xml:space". _________________ Glenn |
|
Back to top |
|
 |
akkypaul |
Posted: Mon Jun 22, 2020 10:54 pm Post subject: |
|
|
 Apprentice
Joined: 30 Jun 2014 Posts: 44 Location: India
|
Hello Vitor,
Thank you for replying.
You are correct. The ReadyAPI tool trims the whitespace (in this case a Space Character) and presents the output.
I confirmed this by feeding the response directly to the backend and they confirmed that they were able confirm that they could see a space in the Request XML that they received. I also confirmed the same with a user trace as suggested.
Quote: |
Secondly, and on the same line, are you sure you want a space? There's a difference between these: |
>> Yes, I understand the difference between them. I am sure that I want to send a space character and also receive a space character but I do not see it in my main flow.
Now, there is a problem with receiving the SPACE character from the backend.
The backend flow sends a field containing a SPACE Character.
To give you a background, I am sending a SOAP request to Backend and getting a SOAP response from it using a SOAP Request Node. The SOAP request node is configured with a WSDL.
In the backend, I am reading an XML file from a File Input node using XMLNSC parser and the backend flow is able to read the SPACE Character just fine.
Code: |
<AnotherField> </AnotherField> |
However, when this backend response is supplied back to the main flow via a SOAP Request Node, it trims that character and presents it as a null field.
Is there anyway in which I can retain that SPACE Character????
 |
|
Back to top |
|
 |
akkypaul |
Posted: Mon Jun 22, 2020 10:57 pm Post subject: |
|
|
 Apprentice
Joined: 30 Jun 2014 Posts: 44 Location: India
|
gbaddeley wrote: |
You may be missing an understanding of "whitespace" in the XML element content space. Adding spaces may cause ambiguities with some parsers, and many will ignore or compact spaces unless they are told otherwise. Do a search for the reserved attribute "xml:space". |
Hello Glen,
Thank you so much for replying.
I read through the "xml:space" documentation and found it to be very helpful. Unfortunately, I would not be able to include this attribute in my XML request and neither would I be able to receive this attribute from the response because of schema restrictions.
 |
|
Back to top |
|
 |
timber |
Posted: Tue Jun 23, 2020 1:35 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Check the XSD definition and the simple type for the offending tag. I wonder if the XSD type has a facet <xs:whitespace value="collapse"/> |
|
Back to top |
|
 |
akkypaul |
Posted: Tue Jun 23, 2020 4:19 am Post subject: |
|
|
 Apprentice
Joined: 30 Jun 2014 Posts: 44 Location: India
|
Thank for your replying timber.
The XSD definition has nothing of this sort.
It has an enumeration though.
Code: |
<xsd:simpleType name="AnotherField">
<xsd:annotation>
<xsd:documentation xml:lang="EN">
<ccts:RepresentationTerm>Code</ccts:RepresentationTerm>
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:token">
<xsd:enumeration value=" "/>
<xsd:enumeration value="A"/>
<xsd:enumeration value="B"/>
<xsd:enumeration value="C"/>
<xsd:enumeration value="D"/>
<xsd:maxLength value="1"/>
</xsd:restriction>
</xsd:simpleType> |
|
|
Back to top |
|
 |
gbaddeley |
Posted: Tue Jun 23, 2020 3:04 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
You may need to rethink the requirement for SPACE character in XML content. Can its meaning be represented by another character? Can it be encoded using & # 032 ; & #160 ; or \u0020 ? Can the SPACE be moved into an attribute in the element start tag? eg. <myelem AnotherField=' '> _________________ Glenn |
|
Back to top |
|
 |
timber |
Posted: Thu Jun 25, 2020 4:52 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
akkypaul said:
Quote: |
The XSD definition has nothing of this sort. |
The xsd says:
Code: |
<xsd:restriction base="xsd:token"> |
The XSD spec says: https://www.w3.org/TR/xmlschema-2/#token
All the information is out there - you just have to know where to look! |
|
Back to top |
|
 |
|