The SOAP Parsing Example
The parsing example,
soap_main.cpp, demonstrates the use of
rwsf::XmlReader to process content from an
any element. To use this type of processing, you need to know the exact format of the XML data within the
any element so you can know exactly the calls to make on the
rwsf::XmlReader object.
This section describes the code in the provided example soap_main.cpp.
The example creates an instance of the class that represents the SOAP envelope, unmarshals the SOAP document into this instance, and retrieves a string that contains the first element in the SOAP body. The example then uses an instance of
rwsf::XmlReader to parse the element.
int main ()
{
tns::EnvelopeElement e; // 1
// Use a C++ try block to handle errors that can occur when
// unmarshaling XML. In this try block, we will output
// the error message to standard err
try {
std::ifstream istrm("soap.xml");
std::stringstream buffer;
buffer << istrm.rdbuf();
std::string xmlContents(buffer.str());
// Unmarshal the XML into the object model
e.unmarshal(xmlContents); // 2
tns::BodyType b = e.getBodyElement(); // 3
tns::BodyType::anyVector av = b.getAnyVector(); // 4
std::string s = av[0]; // 5
// process the entry with the reader
rwsf::XmlReader reader(s); // 6
reader.readElementStart(); // 7
reader.readNextNode(); // 8
std::cout << "Entry name: "
<< reader.getLastName().getQualifiedName() // 9
<< std::endl;
reader.readElementStart(); //10
std::cout << "Symbol name: "
<< reader.getLastName().getQualifiedName() //11
<< std::endl;
reader.readNextNode(); //12
std::cout << "Symbol value: "
<< reader.getLastContent() //13
<< std::endl;
reader.readElementEnd(); //14
reader.readElementEnd(); //15
} catch (const rwsf::XmlParseException &e) {
std::cerr << "Parse error when unmarshaling : "
<< e.what() << std::endl;
return 1;
} catch (const rwsf::Exception &x) {
std::cerr << "Error : " << x.what() << std::endl;
return 1;
}
return 0;
}