Page 1 of 1

PB5.30 CatchXML() failed in unicode mode

Posted: Thu Sep 11, 2014 9:51 am
by uwekel
Hi,

when i receive a string over network and want to parse it, i hand it over to the CatchXML() method for further processing. That works well if "Create unicode executable" is off. With unicode on, it fails.

Here is a sample code to test:

Code: Select all

xml.s = "<item></item>"

;fails if "Create unicode executables" is TRUE
CatchXML(0, @xml, Len(xml))
If XMLStatus(0) = #PB_XML_Success
  Debug "SUCCESS"
Else
  Debug "FAILED"  
EndIf

;if we double the string length, it works
CatchXML(0, @xml, Len(xml) * 2)
If XMLStatus(0) = #PB_XML_Success
  Debug "SUCCESS"  
Else
  Debug "FAILED"  
EndIf
As you can see, the reason is, that the CatchXML() method does not consider that the raw string data is twice the length of the string. If we double the length, it works.

I think, this must be fully handled by the CatchXML() method.

Best regards
Uwe

Re: PB5.30 CatchXML() failed in unicode mode

Posted: Thu Sep 11, 2014 9:59 am
by wilbert
What you are passing is not a string but a memory location and the only logical size in that case is a length in bytes as the manual mentions.
The correct way to use would be

Code: Select all

xml.s = "<item></item>"

CatchXML(0, @xml, StringByteLength(xml))
If XMLStatus(0) = #PB_XML_Success
  Debug "SUCCESS"
Else
  Debug "FAILED"  
EndIf

Re: PB5.30 CatchXML() failed in unicode mode

Posted: Thu Sep 11, 2014 10:14 am
by uwekel
Oh, i did not know that :oops:
Thx a lot!

Re: PB5.30 CatchXML() failed in unicode mode

Posted: Fri Sep 12, 2014 11:58 pm
by Kiffi
or -- a little bit easier -- ParseXML():

Code: Select all

xml.s = "<item></item>"

ParseXML(0, xml)

If XMLStatus(0) = #PB_XML_Success
  Debug "SUCCESS"
Else
  Debug "FAILED"  
EndIf
Greetings ... Peter

Re: PB5.30 CatchXML() failed in unicode mode

Posted: Sat Sep 13, 2014 1:01 pm
by uwekel
Thx Kiffi!
I do not know why i have used CatchXML, but ParseXML is easier to use and is working well :-)