Added method to encode xml content.

This commit is contained in:
Daniel Önnerby 2008-08-16 22:53:05 +00:00
parent 252f06e1b4
commit 709afc9806
2 changed files with 12 additions and 2 deletions

View File

@ -36,7 +36,7 @@
#include "pch.hpp"
#include <core/xml/Writer.h>
#include <core/xml/WriterNode.h>
#include <boost/algorithm/string/replace.hpp>
using namespace musik::core::xml;
@ -154,7 +154,7 @@ void Writer::Send(){
if(node!=this->node){ // Do not send root node
// Send the content and end tag
sendBuffer.append(node->content);
sendBuffer.append(Writer::EncodeSpecialCharacters(node->content));
sendBuffer.append("</"+node->name+">");
}
@ -184,4 +184,12 @@ void Writer::Send(){
}
std::string Writer::EncodeSpecialCharacters(std::string xmlContent){
boost::algorithm::replace_all(xmlContent,"<","&lt;");
boost::algorithm::replace_all(xmlContent,">","&gt;");
boost::algorithm::replace_all(xmlContent,"&","&amp;");
boost::algorithm::replace_all(xmlContent,"\"","&quot;");
boost::algorithm::replace_all(xmlContent,"'","&apos;");
return xmlContent;
}

View File

@ -75,6 +75,8 @@ class Writer : public WriterNode{
std::string sendBuffer;
static std::string EncodeSpecialCharacters(std::string xmlContent);
};
//////////////////////////////////////////////////////////////////////////////