WebParseResponseTag Function

Action

Parses the HTML response and stores the value of a specified attribute in a string variable. The attribute in question can be specified by a tag, an attribute-value pair (which must be part of the tag), the name of the frame, and the nth appearance of these conditions.

Finding the data is not affected by the order of multiple calls to WebParseResponseTag or by calls to other parsing functions (like WebParseResponseTagContent, WebParseResponseData, and so on). The subsequent low-level web function will not return until the request has finished. Other requests started before may run in parallel.

When verifying/parsing an HTML page that consists of multiple frames, you can specify which frame document to verify/parse by specifying the sFrame parameter. By default, all HTML documents of the HTML page are scanned. This applies to HTML pages that are retrieved through a page-level command like WebPageUrl or WebPageLink.

It is important to know that all parsing and verification functions must be specified before the Web API call for which the response data should be parsed/verified. You can specify multiple parse/verification functions before a Web API call. The order of the parse/verification functions is not relevant (Exception: WebParseDataBound and WebVerifyDataBound using the flag WEB_FLAG_SYNCHRON).

Note: If you want to parse a Web server response, you must first call the WebParseResponseHeader function. Then you send the request to the Web server.

Include file

WebAPI.bdh

Syntax

WebParseResponseTag( out sResult        : string,
                     in  nMaxResultLen  : number,
                     in  sTag           : string,
                     in  sAttribute     : string,
                     in  sCondAttribute : string optional,
                     in  sCondValue     : string optional,
                     in  nAppearance    : number optional,
                     in  sFrame         : string optional,
                     out nResultLen     : number optional ): boolean;

Return value

  • true if the parsing modifier could be created successfully

  • false otherwise

Parameter Description
sResult String variable that receives the value of the specified attribute.
nMaxResultLen Maximum length of the string to return. This value must be less than or equal to the size of the string variable sResult.
sTag Tag in which the attribute has to be found.
sAttribute Attribute to search for.
sCondAttribute Attribute of the conditional attribute-value pair that must be present in the tag (optional). If this parameter is omitted, no conditional attribute-value pair is checked.
sCondValue Value of the conditional attribute-value pair that must be present in the result tag (optional).
nAppearance This parameter specifies which instance of the appearance when all conditions are met is the one for which the result is set (optional). If this parameter is omitted the first appearance is taken.
sFrame Frame name where to search (optional). If this parameter is omitted, the whole page is searched. An empty string specifies the top frame.
bBaseDocOnly If this parameter is set to true, only the base document is searched. If sFrame specifies a frame set, the sub frames are not scanned (optional). If this parameter is omitted, all sub frames are searched also.
nResultLen Variable that receives the number of bytes actually copied to sResult (optional).

Example

dcltrans
  transaction TMain
  var
    sResult, sLink, sFrame1, sFrame2: string;
  begin
    WebParseResponseTag(sResult, STRING_COMPLETE, "table", "height");
    WebPageUrl("http://mycompany.com/");
    Print(sResult);
    WebParseResponseTag(sLink, STRING_COMPLETE, "A", "href");
    WebParseResponseTag(sResult,
STRING_COMPLETE, "font", "face", "size", "5", 2);
    WebUrl("http://mycompany.com/Shop/default.htm");
    Print(sLink);
    Print(sResult);

    // "", true ... search only in the base frame set
    WebParseResponseTag(sFrame1,
STRING_COMPLETE, "Frame", "Src", 0,
0, 1, "", true);
    WebParseResponseTag(sFrame2,
STRING_COMPLETE, "Frame", "Src", 0, 0, 2, "", true);
    WebPageUrl("http://mycompany.com/frame/frame.html");
    Print(sFrame1);
    Print(sFrame2);
  end TMain;