85 struct soap *soap = soap_new1(SOAP_XML_STRICT | SOAP_XML_INDENT | SOAP_XML_NOTYPE);
87 _a__address_book *ab = soap_new__a__address_book(soap, -1);
92 fs.open(
"address.xml", std::ios::in);
96 if (soap_read__a__address_book(soap, ab) != SOAP_OK)
98 std::cerr <<
"Error reading address.xml file" << std::endl;
99 soap_stream_fault(soap, std::cerr);
106 std::cout << std::endl <<
"ADDRESS BOOK - An Example XML Data Binding Application" << std::endl << std::endl;
107 for (std::vector<a__address*>::const_iterator i = ab->address.begin(); i != ab->address.end(); ++i)
111 std::cout <<
"Address entry " << (*i)->ID << std::endl;
112 std::cout <<
"Name: " << (*i)->name << std::endl;
113 std::cout <<
"Street: " << (*i)->street << std::endl;
114 std::cout <<
"City: " << (*i)->city << std::endl;
115 std::cout <<
"Zip: " << (*i)->zip << std::endl;
119 std::cout <<
"Country: " << soap_a__ISO_country2s(soap, (*i)->country) <<
122 std::cout <<
"Phone: " << *(*i)->phone << std::endl;
124 std::cout <<
"Mobile: " << *(*i)->mobile << std::endl;
127 std::cout <<
"DOB: " << soap_dateTime2s(soap, *(*i)->dob) << std::endl;
128 std::cout <<
"---------" << std::endl;
133 a__address *a = soap_new_a__address(soap, -1);
135 a->soap_default(soap);
137 a->ID = ab->address.size() + 1;
139 std::cout <<
"Enter a new contact:" << std::endl;
149 soap->error = SOAP_OK;
150 if (soap_s2a__ISO_country(soap, s, &a->country) != SOAP_OK)
151 std::cerr <<
"Not a valid country code" << std::endl;
157 a->phone = soap_new_std__string(soap, -1);
163 a->mobile = soap_new_std__string(soap, -1);
169 a->dob = soap_new_dateTime(soap);
170 if (soap_s2dateTime(soap, s, a->dob) != SOAP_OK)
171 std::cerr <<
"Not a valid ISO 8601 date time (ignored)" << std::endl;
173 soap->error = SOAP_OK;
176 ab->address.push_back(a);
178 std::cout << std::endl <<
"Contact information added." << std::endl;
181 fs.open(
"address.xml", std::ios::out);
184 std::cerr <<
"Cannot create address.xml file" << std::endl;
188 if (soap_write__a__address_book(soap, ab) != SOAP_OK)
190 std::cerr <<
"Error writing address.xml file" << std::endl;
191 soap_stream_fault(soap, std::cerr);
211 printf(
"%-9s> ", prompt);
212 fgets(buf, 80, stdin);
215 for (s = buf + strlen(buf) - 1; s > buf; s--)
223 for (s = buf; *s; s++)
char * user_input(const char *prompt)
A quick-and-dirty user input function: reads string from stdin (up to 80 chars), trims leading and tr...
int main()
Address book application: reads address.xml, displays its content, prompts the user for new contact...