You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
![]()
7 years ago
|
#include "webcc/soap_message.h"
|
||
![]()
8 years ago
|
|
||
|
#include <cassert>
|
||
![]()
7 years ago
|
#include "webcc/xml.h"
|
||
![]()
8 years ago
|
|
||
![]()
7 years ago
|
namespace webcc {
|
||
![]()
8 years ago
|
|
||
|
void SoapMessage::ToXml(std::string* xml_string) {
|
||
|
assert(soapenv_ns_.IsValid() &&
|
||
|
service_ns_.IsValid() &&
|
||
|
!operation_.empty());
|
||
|
|
||
|
pugi::xml_document xdoc;
|
||
|
|
||
|
// TODO:
|
||
|
// When save with format_default, declaration will be generated
|
||
|
// automatically but without encoding.
|
||
|
// pugi::xml_node xdecl = xdoc.prepend_child(pugi::node_declaration);
|
||
|
// xdecl.append_attribute("version").set_value("1.0");
|
||
|
|
||
|
pugi::xml_node xroot = xml::AddChild(xdoc, soapenv_ns_.name, "Envelope");
|
||
|
|
||
|
xml::AddNSAttr(xroot, soapenv_ns_.name, soapenv_ns_.url);
|
||
|
|
||
|
pugi::xml_node xbody = xml::AddChild(xroot, soapenv_ns_.name, "Body");
|
||
|
|
||
|
ToXmlBody(xbody);
|
||
|
|
||
|
xml::XmlStrRefWriter writer(xml_string);
|
||
|
xdoc.save(writer, "\t", pugi::format_default, pugi::encoding_utf8);
|
||
|
}
|
||
|
|
||
|
bool SoapMessage::FromXml(const std::string& xml_string) {
|
||
|
pugi::xml_document xdoc;
|
||
|
pugi::xml_parse_result result = xdoc.load_string(xml_string.c_str());
|
||
|
|
||
|
if (!result) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
pugi::xml_node xroot = xdoc.document_element();
|
||
|
|
||
|
soapenv_ns_.name = xml::GetPrefix(xroot);
|
||
|
soapenv_ns_.url = xml::GetNSAttr(xroot, soapenv_ns_.name);
|
||
|
|
||
|
pugi::xml_node xbody = xml::GetChild(xroot, soapenv_ns_.name, "Body");
|
||
|
if (xbody) {
|
||
|
return FromXmlBody(xbody);
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
![]()
7 years ago
|
} // namespace webcc
|