preload

XML output with WinRunner – 1

Posted by Albert Gareev on Aug 15, 2007 | Categories: Source codeXML Data

Root page: Service Functions – XML

Parent page: Service Functions – XML / WinRunner

Declarations and definitions


#xml rectricted characters 
static const _XML_RESTRICTED[] = {
 0 = 5,
 1 = {"&", "&"},
 2 = {"\"", """},
 3 = {">", ">"},
 4 = {"<", "&lt;"},
 5 = {" ", " "} # web space char
 };

#Flags
static xml_write_mode;

static node_indent;

#XML filespec
public _xml_file_spec;
public _xml_dump[];

#XSL parsers
#"<?xml-stylesheet type=\"text/xsl\" href=\"...*.xsl\"?>"
static xsl_parser = "";

Initialization

public function xml_init() {
 _xml_file_spec = "";
 node_indent = "";
 
 delete _xml_dump[];
 _xml_dump[0] = 0;
 xml_write_mode = TRUE;
}public function xml_file_init(in xml_file, in parser_line) {
 auto rc;
 
 rc = file_open(xml_file, FO_MODE_WRITE);
 if (rc != E_OK) return(rc);

 if (parser_line != "")
  xsl_parser = parser_line;
 
 file_printf(xml_file, "%s\r\n", xsl_parser);
 file_printf(xml_file, "%s\r\n", "");
 file_close(xml_file);
 
 return(E_OK);
}

Parsing

static function xml_str_norm(in s) {
 auto c, i;
 auto res;
 
 c = _XML_RESTRICTED[0];
 res = s;
 for (i=1;i<=c;i++)
  res = str_replace(res, _XML_RESTRICTED[i,0], _XML_RESTRICTED[i,1]);  
  
 return(res); 
}

Control flag

Buffering

static function dump_printf(in format_str, in arg_str) {
 _xml_dump[0]++;
 _xml_dump[_xml_dump[0],"format"] = format_str;
 _xml_dump[_xml_dump[0],"arg"] = arg_str;
}
public function xml_dump_write(in xml_file) {
 auto rc, i;

 rc = file_open(xml_file, FO_MODE_APPEND);
 if (rc != E_OK) return(rc);
 
 for (i=1;i<=_xml_dump[0];i++)
  file_printf(xml_file, _xml_dump[i,"format"], _xml_dump[i,"arg"]);

 file_close(xml_file);
 delete _xml_dump[];
 
 return(E_OK);
}


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.