0

Briefly: My xml string is with wrong encoding. But after using NSLog and copying string from Xcode console the string got right encoding.

Full explanation:

I sent xml string to server with ASIFormDataRequest and encoding:

<?xml version="1.0" encoding="UTF-8"?>

And I got an error 500 "Server can't parse your xml". I thought, that it was an error in my xml. I tried to analyze, I built xml from string from NSArray and NSDictionary. These strings were taken from previous server response and from textfields.

But then I used NSLog("%@", myXmlString). I saw my xml string in Xcode console. I copied the string from console and pasted directly in code, and I sent this coped string to server. And there were no error.

The question: How can I change the string (string encoding) the same way Xcode console change it?

Update

The string from NSLog console:

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns: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:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://com.test/types/AstoriaObjectProperties" xmlns:ns1="http://com.test/wsdl/AstoriaObjectProperties" xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"><env:Body><ns1:setObjectProperties env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><HashMap_1 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID1"/></item></HashMap_1><HashMap_2 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID2"/></item></HashMap_2></ns1:setObjectProperties><ns0:ArrayOfhashMap id="ID1" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap><ns0:ArrayOfhashMap id="ID2" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap></env:Body></env:Envelope>

I used wireshark to get the string server got. Here it is:

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns: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:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://com.test/types/AstoriaObjectProperties" xmlns:ns1="http://com.test/wsdl/AstoriaObjectProperties" xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"><env:Body><ns1:setObjectProperties env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><HashMap_1 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID1"/></item></HashMap_1><HashMap_2 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID2"/></item></HashMap_2></ns1:setObjectProperties><ns0:ArrayOfhashMap id="ID1" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]">...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap><ns0:ArrayOfhashMap id="ID2" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]">...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap></env:Body></env:Envelope>

So, I see additional dots in this xml.

Inspiration
  • 65
  • 1
  • 8

0 Answers0