X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzlexml.cpp;h=bb457223750f3c0c872fb3afa6402251cfb0537b;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=1dea038bfda6359a1e7c93968b6c2c97cec0c9cc;hpb=52c0819bfc1d083c6e0738f75f0d7eeba521295a;p=fms.git diff --git a/src/freenet/introductionpuzzlexml.cpp b/src/freenet/introductionpuzzlexml.cpp index 1dea038..bb45722 100644 --- a/src/freenet/introductionpuzzlexml.cpp +++ b/src/freenet/introductionpuzzlexml.cpp @@ -11,25 +11,33 @@ IntroductionPuzzleXML::IntroductionPuzzleXML() std::string IntroductionPuzzleXML::GetXML() { - TiXmlDocument td; - TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8",""); - TiXmlElement *tid; - TiXmlPrinter tp; + Poco::AutoPtr doc=new Poco::XML::Document; + //TiXmlDocument td; + //TiXmlDeclaration *tdec=new TiXmlDeclaration("1.0","UTF-8",""); + Poco::XML::Element *root=doc->createElement("IntroductionPuzzle"); + //TiXmlElement *tid; + //TiXmlPrinter tp; - td.LinkEndChild(tdec); - tid=new TiXmlElement("IntroductionPuzzle"); - td.LinkEndChild(tid); + doc->appendChild(root); + //td.LinkEndChild(tdec); + //tid=new TiXmlElement("IntroductionPuzzle"); + //td.LinkEndChild(tid); - tid->LinkEndChild(XMLCreateTextElement("Type",m_type)); + root->appendChild(XMLCreateTextElement(doc,"Type",m_type)); + //tid->LinkEndChild(XMLCreateTextElement("Type",m_type)); - tid->LinkEndChild(XMLCreateCDATAElement("UUID",m_uuid)); + root->appendChild(XMLCreateCDATAElement(doc,"UUID",m_uuid)); + //tid->LinkEndChild(XMLCreateCDATAElement("UUID",m_uuid)); - tid->LinkEndChild(XMLCreateTextElement("MimeType",m_mimetype)); + root->appendChild(XMLCreateTextElement(doc,"MimeType",m_mimetype)); + //tid->LinkEndChild(XMLCreateTextElement("MimeType",m_mimetype)); - tid->LinkEndChild(XMLCreateTextElement("PuzzleData",m_puzzledata)); + root->appendChild(XMLCreateTextElement(doc,"PuzzleData",m_puzzledata)); + //tid->LinkEndChild(XMLCreateTextElement("PuzzleData",m_puzzledata)); - td.Accept(&tp); - return std::string(tp.CStr()); + //td.Accept(&tp); + //return std::string(tp.CStr()); + return GenerateXML(doc); } void IntroductionPuzzleXML::Initialize() @@ -42,6 +50,59 @@ void IntroductionPuzzleXML::Initialize() const bool IntroductionPuzzleXML::ParseXML(const std::string &xml) { + bool parsed=false; + Poco::XML::DOMParser dp; + + Initialize(); + + try + { + Poco::AutoPtr doc=dp.parseString(FixCDATA(xml)); + Poco::XML::Element *root=XMLGetFirstChild(doc,"IntroductionPuzzle"); + Poco::XML::Element *txt=NULL; + + txt=XMLGetFirstChild(root,"Type"); + if(txt) + { + if(txt->firstChild()) + { + m_type=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } + } + txt=XMLGetFirstChild(root,"UUID"); + if(txt) + { + if(txt->firstChild()) + { + m_uuid=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } + } + txt=XMLGetFirstChild(root,"MimeType"); + if(txt) + { + if(txt->firstChild()) + { + m_mimetype=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } + } + txt=XMLGetFirstChild(root,"PuzzleData"); + if(txt) + { + if(txt->firstChild()) + { + m_puzzledata=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } + } + + parsed=true; + } + catch(...) + { + } + + return parsed; + + /* TiXmlDocument td; td.Parse(xml.c_str()); @@ -55,19 +116,19 @@ const bool IntroductionPuzzleXML::ParseXML(const std::string &xml) txt=hnd.FirstChild("IntroductionPuzzle").FirstChild("Type").FirstChild().ToText(); if(txt) { - m_type=txt->ValueStr(); + m_type=SanitizeSingleString(txt->ValueStr()); } txt=hnd.FirstChild("IntroductionPuzzle").FirstChild("UUID").FirstChild().ToText(); if(txt) { - m_uuid=txt->ValueStr(); + m_uuid=SanitizeSingleString(txt->ValueStr()); } txt=hnd.FirstChild("IntroductionPuzzle").FirstChild("MimeType").FirstChild().ToText(); if(txt) { - m_mimetype=txt->ValueStr(); + m_mimetype=SanitizeSingleString(txt->ValueStr()); } txt=hnd.FirstChild("IntroductionPuzzle").FirstChild("PuzzleData").FirstChild().ToText(); @@ -83,4 +144,5 @@ const bool IntroductionPuzzleXML::ParseXML(const std::string &xml) { return false; } + */ }