[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Parser Problems
Hello Scott,
Thank you (and others) for all your help on this. That is faster service
than I get at the local McDonalds. I'm excited to get the "beta" and test
it out. I'm sure it will work perfectly.
Regards,
-Tom
-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
[mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Sunday, October 09, 2011 11:51 PM
To: ftpapi@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Parser Problems
Hello,
>
> Honestly, I already have the code updates completed. I would've posted
> them yesterday, but you told me not to spend my weekend working on it,
> so I was going to wait until Monday to tell you. :-)
>
If you'd like to try it, grab the latest "beta" copy from here:
http://www.scottklement.com/httpapi/beta
The new feature is called http_XmlReturnUcs(*on/*off). You call this
procedure before asking HTTPAPI to parse XML. If you pass *ON, it'll
return the output to your program in UCS-2 (Unicode) format. If you
pass *OFF, the XML parser will return EBCDIC (this is the default.)
This setting will be remembered until you call http_XmlReturnUcs()
again, or until the activation group containing HTTPAPIR4 is ended. So
if you call the XML parser multiple times, the setting will be retained
(unless you explicitly change it.)
In your case, Tom, you'll want to do this:
h dftactgrp(*no) bnddir('HTTPAPI':'QC2LE')
/define WEBFORMS
/copy httpapi_h
D Parse1 PR
D UserData likeds(value_t)
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value likeds(value_t) const
D Parse2 PR
D UserData * value
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 65535A varying const
D value_t ds qualified
D buf *
D len 10i 0
D result ds likeds(value_t)
D url s 2000a varying
D rc s 10i 0
D myForm s like(WEBFORM)
D myPostData s *
D myPostDataLen s 10i 0
/free
http_debug(*on : '/tmp/TomThomsonTest_log.txt');
http_XmlReturnPtr(*on);
http_XmlReturnUcs(*on);
url = 'http://api.netroomz.com.au/allotmentserviceextended.asmx+
/GetAllotmentList';
myForm = WEBFORM_open();
WEBFORM_setVar( myForm : 'callerID': 'XXXXXXXXXXX' );
WEBFORM_setVar( myForm : 'username': 'YYY' );
WEBFORM_setVar( myForm : 'password': 'ZZZZZZ' );
WEBFORM_postData( myForm: myPostData: myPostDataLen );
rc = http_post_xml( url
: myPostData
: myPostDataLen
: *null
: %paddr(Parse1)
: %addr(Result)
: HTTP_TIMEOUT
: *omit
: 'application/x-www-form-urlencoded' );
WEBFORM_close(myForm);
if rc <> 1;
http_crash();
endif;
http_XmlReturnUcs(*off);
http_XmlReturnPtr(*off);
rc = http_parse_xml_string( Result.buf
: Result.len
: 1200
: *null
: %paddr(Parse2)
: *null );
if (rc < 0);
http_crash();
endif;
if (Result.buf <> *null);
dealloc Result.buf;
endif;
*inlr = *on;
/end-free
P Parse1 B
D PI
D UserData likeds(value_t)
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value likeds(value_t) const
D memcpy pr * extproc('memcpy')
D dest * value
D src * value
D size 10u 0 value
/free
if name = 'string';
UserData.len = value.len;
if UserData.buf = *null;
UserData.buf = %alloc(userdata.len);
else;
UserData.buf = %realloc(UserData.buf:userdata.len);
endif;
memcpy( UserData.buf: Value.buf: UserData.len);
endif;
/end-free
P E
P Parse2 B
D PI
D UserData * value
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value 65535A varying const
/free
if name = 'ShortDescription';
// I did this just for debugging, so
// I can set a breakpoint below, and
// see the that I'm getting the proper
// result.
if %scan('Children': value) > 0;
dsply 'found';
endif;
endif;
/end-free
P E
You'll notice that I called http_XmlReturnUcs() twice. The first call
tells HTTPAPI to return UCS (Unicode) data. It uses the Parse1()
subprocedure to load the "inner XML" into a memory buffer. Since this
is true Unicode, the slanted double quotes will remain slanted double
quotes...
Then, after that, it turns http_XmlReturnUcs() off again, so when it
does the 2nd parse, the data will be returned in EBCDIC. When it calls
http_parse_xml_string(), it passes a CCSID 1200 (which is UTF-16) and
that tells the XML parser to treat the input as Unicode (rather than
EBCDIC). It uses a procedure called Parse2() for the XML parsing.
When Parse2() gets the data, it'll be in EBCDIC. The slanted double
quote is translated to x'3F' -- but this is no problem at this point,
since the XML parsing is complete. (Plus, the data should now be fed in
small enough pieces translate it with %xlate or %scan/%replace.)
Hope that helps.
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------