PB5.30 CatchXML() failed in unicode mode

Just starting out? Need help? Post your questions and find answers here.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

PB5.30 CatchXML() failed in unicode mode

Post 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
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

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

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

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

Post by uwekel »

Oh, i did not know that :oops:
Thx a lot!
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

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

Post 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
Hygge
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

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

Post by uwekel »

Thx Kiffi!
I do not know why i have used CatchXML, but ParseXML is easier to use and is working well :-)
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
Post Reply