00001
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
#include <iostream>
00091
#include <fstream>
00092
00093
#include "addressH.h"
00094
#include "a.nsmap"
00095
00103
char *
user_input(
const char *prompt);
00104
00109 int main()
00110 {
00111
00112
00113
struct soap *soap = soap_new1(SOAP_XML_STRICT | SOAP_XML_INDENT | SOAP_XML_CANONICAL);
00114
00115
_a__address_book *ab = soap_new__a__address_book(soap, -1);
00116
00117 std::fstream fs;
00118
00119
00120 fs.open(
"address.xml", std::ios::in);
00121
if (fs)
00122 {
00123 soap->is = &fs;
00124
if (soap_read__a__address_book(soap, ab) != SOAP_OK)
00125 {
00126 std::cerr <<
"Error reading address.xml file" << std::endl;
00127 soap_stream_fault(soap, std::cerr);
00128 exit(1);
00129 }
00130 fs.close();
00131 }
00132
00133
00134 std::cout << std::endl <<
"ADDRESS BOOK - An Example XML Data Binding Application" << std::endl << std::endl;
00135
for (std::vector<a__address*>::const_iterator i = ab->
address.begin(); i != ab->
address.end(); ++i)
00136 {
00137
if (*i)
00138 {
00139 std::cout <<
"Address entry " << (*i)->ID << std::endl;
00140 std::cout <<
"Name: " << (*i)->name << std::endl;
00141 std::cout <<
"Street: " << (*i)->street << std::endl;
00142 std::cout <<
"City: " << (*i)->city << std::endl;
00143 std::cout <<
"Zip: " << (*i)->zip << std::endl;
00144
00145
00146
00147 std::cout <<
"Country: " << soap_a__ISO_country2s(soap, (*i)->country) <<
00148 std::endl;
00149
if ((*i)->phone)
00150 std::cout <<
"Phone: " << *(*i)->phone << std::endl;
00151
if ((*i)->mobile)
00152 std::cout <<
"Mobile: " << *(*i)->mobile << std::endl;
00153
00154
if ((*i)->dob)
00155 std::cout <<
"DOB: " << soap_dateTime2s(soap, *(*i)->dob) << std::endl;
00156 std::cout <<
"---------" << std::endl;
00157 }
00158 }
00159
00160
00161
a__address *a = soap_new_a__address(soap, -1);
00162
00163 a->soap_default(soap);
00164
00165 a->
ID = ab->
address.size() + 1;
00166
00167 std::cout <<
"Enter a new contact:" << std::endl;
00168 a->
name =
user_input(
"Name");
00169 a->
street =
user_input(
"Street");
00170 a->
city =
user_input(
"City");
00171 a->
zip =
user_input(
"Zip");
00172
char *s =
user_input(
"Country");
00173
00174
00175
if (soap_s2a__ISO_country(soap, s, &a->
country) != SOAP_OK)
00176 std::cerr <<
"Not a valid country code" << std::endl;
00177
if (*(s =
user_input(
"Phone")))
00178 {
00179
00180 a->
phone = soap_new_std__string(soap, -1);
00181 *a->
phone = s;
00182 }
00183
if (*(s =
user_input(
"Mobile")))
00184 {
00185
00186 a->
mobile = soap_new_std__string(soap, -1);
00187 *a->
mobile = s;
00188 }
00189
00190
00191 ab->
address.push_back(a);
00192
00193 std::cout << std::endl <<
"Contact information added." << std::endl;
00194
00195
00196 fs.open(
"address.xml", std::ios::out);
00197
if (!fs)
00198 {
00199 std::cerr <<
"Cannot create address.xml file" << std::endl;
00200 exit(1);
00201 }
00202 soap->os = &fs;
00203
if (soap_write__a__address_book(soap, ab) != SOAP_OK)
00204 {
00205 std::cerr <<
"Error writing address.xml file" << std::endl;
00206 soap_stream_fault(soap, std::cerr);
00207 exit(1);
00208 }
00209 fs.close();
00210
00211
00212 soap_destroy(soap);
00213
00214 soap_end(soap);
00215
00216 soap_free(soap);
00217
00218
return 0;
00219 }
00220
00221 char *
user_input(
const char *prompt)
00222 {
00223
static char buf[80];
00224
char *s;
00225
00226 printf(
"%-9s> ", prompt);
00227 fgets(buf, 80, stdin);
00228
00229
00230
for (s = buf + strlen(buf) - 1; s > buf; s--)
00231 {
00232
if (*s >
' ')
00233
break;
00234 }
00235 s[1] =
'\0';
00236
00237
00238
for (s = buf; *s; s++)
00239 {
00240
if (*s >
' ')
00241
break;
00242 }
00243
00244
return s;
00245 }