OpenVMS Source Code Demos
DOM2_HACK.C
//=====================================================================================================================
// title : DOM2_HACK.C (developed in folder //gsoap-2.8.3/gsoap/samples/calc/ )
// author : Neil Rieck
// created: 2011-09-19
// notes :
// 1) This example was derived from gSOAP docs like: "//gsoap-2.8.3/gsoap/doc/dom/html/index.html"
// 2) Code remarked with the phrase "HP-C" is required for use with HP-C on OpenVMS-8.4
// 3) Additional info came from the "gSOAP 2.8.9 User Guide" as well as inspecting file included file:
// "//gsoap-2.8.3/include/stdsoap2.h" (specifically, the declaration of "struct SOAP_STD_API soap")
//=====================================================================================================================
// ver who when what
// --- --- -------- ---------------------------------------------------------------------------------------------------
// 100 NSR 20110919 1. original effort (in my ITSM project directory)
// 102 NSR 20110920 1. changes so program will compile properly under HP-C for OpenVMS
// 103 NSR 20110921 1. playing with input/output switches
// 104 NSR 20120815 1. moved to folder //gsoap-2.8.3/gsoap/samples/calc/
// 105 NSR 20120816 1. added some code to attempt DOM-walking
//=====================================================================================================================
// build notes for OpenVMS:
//---------------------------------------------------------------------------------------------------------------------
// step-1 : $ wsdl2h :== $gsoap$root:[000000.bin]wsdl2h.exe
// $ wsdl2h "-c" "-d" "-s" "-o" calc.h calc.wsdl
// generates: calc.h
//---------------------------------------------------------------------------------------------------------------------
// step-2 : $ soapcpp2 :== $gsoap$root:[bin]soapcpp2.exe
// $ soapcpp2 "-c" "-I"gsoap$root:[import] calc.h
// generates: CALC.NSMAP <<--- needed in this client program
// SOAPC.C
// SOAPCLIENT.C
// SOAPCLIENTLIB.C
// SOAPH.H <<--- needed in this client program
// SOAPSERVER.C
// SOAPSERVERLIB.C
// SOAPSTUB.H
// CALC_ADD_REQ.XML -+- not created with switch "-x"
// CALC_ADD_RES.XML -+
// CALC_DIV_REQ.XML -+
// CALC_DIV_RES.XML -+
// CALC_MUL_REQ.XML -+
// CALC_MUL_RES.XML -+
// CALC_POW_REQ.XML -+
// CALC_POW_RES.XML -+
// CALC_SUB_REQ.XML -+
// CALC_SUB_RES.XML -+
//---------------------------------------------------------------------------------------------------------------------
// step-3 : $ cc/names=(as_is,shortened)/prefix=all/float=ieee/ieee=denorm -
// /define=(WITH_DOM) -
// /warning=(disable=EMPTYSTRUCT) -
// /include=gsoap$root:[include] -
// dom_hack.c
//---------------------------------------------------------------------------------------------------------------------
// step-4 : repeat "cc" compile for files:
// SOAPC.C
// SOAPCLIENT.C
//---------------------------------------------------------------------------------------------------------------------
// step-5 : $ link/share=dom_hack.exe -
// dom_hack.obj, -
// soapc.obj, -
// sys$input/opt
// gsoap$root:[lib]gsoap.olb/lib
// gsoap$root:[lib]gsoapdom.olb/lib
// GSMATCH=LEQUAL,1,0
// case_sensitive=YES
// $
//---------------------------------------------------------------------------------------------------------------------
// test : $ yada == "$"+ f$environment("DEFAULT") +"dom_hack.exe"
// $ yada
//=====================================================================================================================
//
// gSOAP headers
//
#include "soapH.h" // generated by soapcpp2
#include "calc.NSMAP" // generated by soapcpp2
//
// "C" stuff
//
#include <stdio.h> // standard i/o
#include <stdlib.h> // standard library
#include <string.h> // string support
#include <wchar.h> //
//
char my_file[] = "CALC_ADD_REQ.XML"; //
FILE *yada; //
//==============================================================
// main()
//==============================================================
int main(int argc, char **argv) {
printf("-i-declaring dom\n"); //
struct soap_dom_element dom; // hp-c needs struct
struct soap_dom_element *iter; // need these for my DOM-walker
struct soap_dom_attribute *attr; // ditto
//------------------------------------------------------
// some run-time flags from page 100 of "gSOAP 2.8.9 User Guide"
//
// input flags:
// SOAP_XML_IGNORENS - in: ignores the use of XML namespaces in input
// SOAP_XML_STRICT - in: XML strict validation
// SOAP_C_NOIOB - in: do not fault with SOAP_IOB
//
// in-out flags:
// SOAP_XML_TREE - in: serialize data as XML trees (no multi-ref, duplicate data when necessary)
// - out: ignore id attributes (do not resolve id-ref)
// SOAP_C_UTFSTRING - in&out: (de)serialize 8-bit strings "as is" (MUST have UTF-8 encoded content)
// SOAP_C_MBSTRING - in&out: enable multibyte character support (depends on locale)
//
// output flags:
// SOAP_XML_CANONICAL - out: produces canonical XML output
// SOAP_XML_DEFAULTNS - out: produces xmlns=". . . " default binding namespaced output
// SOAP_XML_GRAPH - out: serialize data as an XML graph with inline multi-ref (SOAP 1.2 default)
// SOAP_XML_INDENT - out: produces indented XML output
// SOAP_XML_NIL - out: serialize NULL data as xsi:nil elements (omit by default)
// SOAP_XML_NOTYPE - out: disable xsi:type attributes
// SOAP_C_NILSTRING - out: serialize empty strings as nil (ommited element)
// unknown:
// SOAP_XML_DOM -
// SOAP_DOM_TREE -
// SOAP_DOM_NODE -
// SOAP_DOM_ASIS -
//------------------------------------------------------
dom.soap = soap_new(); // this call has no parameters
// soap_set_imode(dom.soap, SOAP_DOM_NODE | SOAP_XML_STRICT); // set input bits
soap_set_imode(dom.soap, SOAP_XML_DOM ); // set input bits
soap_set_omode(dom.soap, SOAP_XML_GRAPH | SOAP_XML_INDENT); // set output bits
//
// input from stdin
//
// dom.soap->recvfd = fileno(stdin); // hp-c needs fileno()
//
// input from a file
//
printf("-i-opening file: %s\n",my_file);
yada = fopen(my_file, "r");
dom.soap->recvfd = fileno(yada);
printf("-i-redirect outout\n"); //
dom.soap->sendfd = fileno(stdout); // hp-c needs fileno()
//
printf("-i-begin soap recv\n");
if (soap_begin_recv(dom.soap)
|| NULL != soap_in_xsd__anyType(dom.soap, NULL, &dom, NULL)
|| soap_end_recv(dom.soap))
{
printf("soap error: %d\n",dom.soap->error);
printf("parse error\n");
soap_print_fault(dom.soap, stdout);
soap_print_fault_location(dom.soap, stdout);
}
printf("-i-soap begin send\n");
if (soap_begin_send(dom.soap))
printf("output error(1)\n");
printf("-i-stage 5\n");
// dom.soap->ns = 2; // note: must use this to omit namespaces table dumping
if (soap_out_xsd__anyType(dom.soap, NULL, 0, &dom, NULL)
|| soap_end_send(dom.soap))
printf("output error(2)\n");
//
// walking across my loaded DOM
//
printf("\n-i-stage 6 (DOM walker)\n");
for (iter = &dom; iter; iter = soap_dom_next_element(iter)) {
printf("-i-elememt name: %s ----------\n",(*iter).name);
if ((*iter).nstr!=0)
printf("-i- nstr: %s\n",(*iter).nstr);
printf("-i- type: %d\n",(*iter).type);
if ((*iter).data!=0)
printf("-i- data: %s\n",(*iter).data);
if ((*iter).wide!=0)
printf("-i- wide: %S\n",(*iter).wide); // caveat: data type is: wchar_t
for (attr = iter->atts; attr; attr = soap_dom_next_attribute(attr)) {
printf("-i-attribute name: %s\n",(*attr).name);
if ((*attr).nstr!=0)
printf("-i- nstr: %s\n",(*attr).nstr);
printf("-i- data: %s\n",(*attr).data);
}
}
//
// cleanup and exit
//
printf("-i-stage 7\n");
soap_print_fault(dom.soap, stderr);
soap_print_fault_location(dom.soap, stderr);
soap_destroy(dom.soap);
soap_end(dom.soap);
soap_done(dom.soap);
free(dom.soap);
printf("-i-adios\n");
}
//========================================