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.
93 lines
2.9 KiB
C
93 lines
2.9 KiB
C
![]()
7 years ago
|
#ifndef WEBCC_SOAP_XML_H_
|
||
|
#define WEBCC_SOAP_XML_H_
|
||
![]()
8 years ago
|
|
||
![]()
8 years ago
|
// XML utilities.
|
||
![]()
8 years ago
|
|
||
![]()
8 years ago
|
#include <string>
|
||
![]()
8 years ago
|
#include "pugixml/pugixml.hpp"
|
||
|
|
||
![]()
7 years ago
|
namespace webcc {
|
||
![]()
7 years ago
|
namespace soap_xml {
|
||
![]()
8 years ago
|
|
||
![]()
8 years ago
|
// Split the node name into namespace prefix and real name.
|
||
|
// E.g., if the node name is "soapenv:Envelope", it will be splited to
|
||
|
// "soapenv" and "Envelope".
|
||
|
void SplitName(const pugi::xml_node& xnode,
|
||
|
std::string* prefix = NULL,
|
||
|
std::string* name = NULL);
|
||
![]()
8 years ago
|
|
||
|
// Get the namespace prefix from node name.
|
||
![]()
8 years ago
|
// E.g., if the node name is "soapenv:Envelope", NS prefix will be "soapenv".
|
||
|
std::string GetPrefix(const pugi::xml_node& xnode);
|
||
![]()
8 years ago
|
|
||
![]()
8 years ago
|
// Get the node name without namespace prefix.
|
||
|
std::string GetNameNoPrefix(const pugi::xml_node& xnode);
|
||
![]()
8 years ago
|
|
||
![]()
8 years ago
|
// Add a child with the given name which is prefixed by a namespace.
|
||
![]()
8 years ago
|
// E.g., AppendChild(xnode, "soapenv", "Envelope") will append a child with
|
||
|
// name "soapenv:Envelope".
|
||
![]()
8 years ago
|
pugi::xml_node AddChild(pugi::xml_node& xnode,
|
||
|
const std::string& ns,
|
||
|
const std::string& name);
|
||
![]()
8 years ago
|
|
||
|
pugi::xml_node GetChild(pugi::xml_node& xnode,
|
||
|
const std::string& ns,
|
||
|
const std::string& name);
|
||
|
|
||
![]()
8 years ago
|
// TODO: Remove
|
||
![]()
8 years ago
|
pugi::xml_node GetChildNoNS(pugi::xml_node& xnode,
|
||
|
const std::string& name);
|
||
|
|
||
![]()
8 years ago
|
// Add an attribute with the given name which is prefixed by a namespace.
|
||
|
void AddAttr(pugi::xml_node& xnode,
|
||
![]()
8 years ago
|
const std::string& ns,
|
||
|
const std::string& name,
|
||
|
const std::string& value);
|
||
|
|
||
|
// Append "xmlns" attribute.
|
||
|
// E.g., if the namespace is
|
||
|
// { "soapenv", "http://schemas.xmlsoap.org/soap/envelope/" }
|
||
|
// the attribute added will be
|
||
|
// xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
||
|
void AddNSAttr(pugi::xml_node& xnode,
|
||
|
const std::string& ns_name,
|
||
|
const std::string& ns_url);
|
||
|
|
||
|
// Get namespace attribute value.
|
||
|
// E.g., if the given namespace name is "soapenv", the value of
|
||
|
// attribute "xmlns:soapenv" will be returned.
|
||
|
std::string GetNSAttr(pugi::xml_node& xnode,
|
||
|
const std::string& ns_name);
|
||
![]()
8 years ago
|
|
||
|
// An XML writer writing to a referenced string.
|
||
|
// Example:
|
||
|
// pugi::xml_document xdoc;
|
||
|
// ...
|
||
|
// std::string xml_string;
|
||
|
// XmlStrRefWriter writer(&xml_string);
|
||
![]()
8 years ago
|
// xdoc.save(writer, "\t", pugi::format_default, pugi::encoding_utf8);
|
||
![]()
8 years ago
|
class XmlStrRefWriter : public pugi::xml_writer {
|
||
|
public:
|
||
|
explicit XmlStrRefWriter(std::string* result)
|
||
|
: result_(result) {
|
||
|
result_->clear();
|
||
|
}
|
||
|
|
||
|
virtual void write(const void* data, size_t size) override {
|
||
|
result_->append(static_cast<const char*>(data), size);
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
std::string* result_;
|
||
|
};
|
||
|
|
||
![]()
7 years ago
|
// Print the XML string to output stream in pretty format.
|
||
|
bool PrettyPrint(std::ostream& os,
|
||
|
const std::string& xml_string,
|
||
|
const char* indent = "\t");
|
||
![]()
8 years ago
|
|
||
![]()
7 years ago
|
} // namespace soap_xml
|
||
![]()
7 years ago
|
} // namespace webcc
|
||
![]()
8 years ago
|
|
||
![]()
7 years ago
|
#endif // WEBCC_SOAP_XML_H_
|