X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzlexml.cpp;h=bb457223750f3c0c872fb3afa6402251cfb0537b;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=12cc8e3f7802c4b5b39c31353714ccc44437221f;hpb=1230cc420c955e75051d011d964bc68f061ba08c;p=fms.git diff --git a/src/freenet/introductionpuzzlexml.cpp b/src/freenet/introductionpuzzlexml.cpp index 12cc8e3..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()); @@ -83,4 +144,5 @@ const bool IntroductionPuzzleXML::ParseXML(const std::string &xml) { return false; } + */ }