X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzlexml.cpp;h=735ddf9728443bcf252e6fe3df7e0134ad184ec5;hb=76805933f794915a72b7f0a21b12af6654759f4f;hp=12cc8e3f7802c4b5b39c31353714ccc44437221f;hpb=1230cc420c955e75051d011d964bc68f061ba08c;p=fms.git diff --git a/src/freenet/introductionpuzzlexml.cpp b/src/freenet/introductionpuzzlexml.cpp index 12cc8e3..735ddf9 100644 --- a/src/freenet/introductionpuzzlexml.cpp +++ b/src/freenet/introductionpuzzlexml.cpp @@ -11,25 +11,20 @@ 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; + Poco::AutoPtr root=doc->createElement("IntroductionPuzzle"); - td.LinkEndChild(tdec); - tid=new TiXmlElement("IntroductionPuzzle"); - td.LinkEndChild(tid); + doc->appendChild(root); - tid->LinkEndChild(XMLCreateTextElement("Type",m_type)); + root->appendChild(XMLCreateTextElement(doc,"Type",m_type)); - tid->LinkEndChild(XMLCreateCDATAElement("UUID",m_uuid)); + root->appendChild(XMLCreateCDATAElement(doc,"UUID",m_uuid)); - tid->LinkEndChild(XMLCreateTextElement("MimeType",m_mimetype)); + root->appendChild(XMLCreateTextElement(doc,"MimeType",m_mimetype)); - tid->LinkEndChild(XMLCreateTextElement("PuzzleData",m_puzzledata)); + root->appendChild(XMLCreateTextElement(doc,"PuzzleData",m_puzzledata)); - td.Accept(&tp); - return std::string(tp.CStr()); + return GenerateXML(doc); } void IntroductionPuzzleXML::Initialize() @@ -42,45 +37,55 @@ void IntroductionPuzzleXML::Initialize() const bool IntroductionPuzzleXML::ParseXML(const std::string &xml) { - TiXmlDocument td; - td.Parse(xml.c_str()); + bool parsed=false; + Poco::XML::DOMParser dp; - if(!td.Error()) - { - TiXmlText *txt; - TiXmlHandle hnd(&td); + Initialize(); - Initialize(); + try + { + Poco::AutoPtr doc=dp.parseString(FixCDATA(xml)); + Poco::XML::Element *root=XMLGetFirstChild(doc,"IntroductionPuzzle"); + Poco::XML::Element *txt=NULL; - txt=hnd.FirstChild("IntroductionPuzzle").FirstChild("Type").FirstChild().ToText(); + txt=XMLGetFirstChild(root,"Type"); if(txt) { - m_type=SanitizeSingleString(txt->ValueStr()); + if(txt->firstChild()) + { + m_type=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } } - - txt=hnd.FirstChild("IntroductionPuzzle").FirstChild("UUID").FirstChild().ToText(); + txt=XMLGetFirstChild(root,"UUID"); if(txt) { - m_uuid=SanitizeSingleString(txt->ValueStr()); + if(txt->firstChild()) + { + m_uuid=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } } - - txt=hnd.FirstChild("IntroductionPuzzle").FirstChild("MimeType").FirstChild().ToText(); + txt=XMLGetFirstChild(root,"MimeType"); if(txt) { - m_mimetype=SanitizeSingleString(txt->ValueStr()); + if(txt->firstChild()) + { + m_mimetype=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } } - - txt=hnd.FirstChild("IntroductionPuzzle").FirstChild("PuzzleData").FirstChild().ToText(); + txt=XMLGetFirstChild(root,"PuzzleData"); if(txt) { - m_puzzledata=txt->ValueStr(); + if(txt->firstChild()) + { + m_puzzledata=SanitizeSingleString(txt->firstChild()->getNodeValue()); + } } - return true; - + parsed=true; } - else + catch(...) { - return false; } + + return parsed; }