From bfb9d10c4c4487de5be67d1ee2d240f3291abb23 Mon Sep 17 00:00:00 2001 From: Brian Caine Date: Wed, 23 Jan 2008 20:52:18 -0500 Subject: [PATCH] Revert "Finished up the XMLParsing functions to parse sprite xml files." This reverts commit 9cb30616ead6e068a3b6a89cb1b6935a86175b26. --- src/XMLParser.cpp | 74 ++++++++++--------------------------------------------- src/XMLParser.h | 3 +-- 2 files changed, 14 insertions(+), 63 deletions(-) diff --git a/src/XMLParser.cpp b/src/XMLParser.cpp index e48004a..1ee6f33 100644 --- a/src/XMLParser.cpp +++ b/src/XMLParser.cpp @@ -54,10 +54,11 @@ XMLParser::~XMLParser() xmlCleanupParser(); } -bool XMLParser::validateXMLData(xmlDocPtr document, std::string schema) +bool XMLParser::validateXMLData(std::string data, std::string schema) { bool results; + xmlDocPtr document = 0; xmlDocPtr relax_doc = 0; xmlRelaxNGParserCtxtPtr relax_context = 0; @@ -71,6 +72,13 @@ bool XMLParser::validateXMLData(xmlDocPtr document, std::string schema) if (results) { + document = xmlCtxtReadMemory(context_pointer, data.c_str(), + data.size(), 0, 0, XML_PARSE_RECOVER); + results = static_cast(document); + } + + if (results) + { relax_context = xmlRelaxNGNewDocParserCtxt(relax_doc); results = static_cast(relax_context); } @@ -92,6 +100,9 @@ bool XMLParser::validateXMLData(xmlDocPtr document, std::string schema) // clean up + if (document) + xmlFreeDoc(document); + if (relax_doc) xmlFreeDoc(relax_doc); @@ -122,7 +133,7 @@ XMLS_Results XMLParser::parseSprite(std::string input) results.error = !document; if (!results.error) - results.error = !validateXMLData(document, XMLS_RELAXNG); + results.error = !validateXMLData(input, XMLS_RELAXNG); // parse @@ -233,42 +244,6 @@ XMLS_Sprite XMLParser::parseSpriteSprite(xmlNode *top) XMLS_Sprite results; results.error = true; - if (std::string((char*)top->name) != XMLS_SPRITE) - return results; - else - results.error = false; - - xmlNode* cur; - for (cur = top->children; cur; cur = cur->next) - if (cur->type == XML_ELEMENT_NODE) - { - if (std::string((char*)cur->name) == XMLS_NAME) - results.name = std::string((char*)cur->children->content); - - if (std::string((char*)cur->name) == XMLS_ITEMS) - results.items = parseSpriteItems(cur); - - if (std::string((char*)cur->name) == XMLS_SEQUENCE) - results.frames = parseSpriteFrames(cur); - } - - return results; -} - -std::vector XMLParser::parseSpriteItems(xmlNode* top) -{ - std::vector results; - - if (std::string((char*)top->name) != XMLS_ITEMS) - return results; - - xmlNode* cur; - for (cur = top->children; cur; cur = cur->next) - if (cur->type == XML_ELEMENT_NODE) - { - results.push_back(std::string((char*)cur->children->content)); - } - return results; } @@ -276,29 +251,6 @@ std::vector XMLParser::parseSpriteFrames(xmlNode* top) { std::vector results; - if (std::string((char*)top->name) != XMLS_SEQUENCE) - return results; - - xmlNode* cur; - for (cur = top->children; cur; cur = cur->next) - if (cur->type == XML_ELEMENT_NODE) - { - xmlNode* frame_cur; - Frame temp; - for (frame_cur = cur->children; frame_cur; frame_cur = frame_cur->next) - if (frame_cur->type = XML_ELEMENT_NODE) - { - if (std::string((char*)frame_cur->name) == XMLS_ITEM) - temp.frame = strtol((char*)frame_cur->children->content, 0, 10); - - if (std::string((char*)frame_cur->name) == XMLS_DURATION) - temp.duration = strtol((char*) - frame_cur->children->content, 0, 10); - } - - results.push_back(temp); - } - return results; } diff --git a/src/XMLParser.h b/src/XMLParser.h index 47e16ca..b72f68b 100644 --- a/src/XMLParser.h +++ b/src/XMLParser.h @@ -96,7 +96,7 @@ namespace fragrant static XMLParser* getXMLParser(); ~XMLParser(); - bool validateXMLData(xmlDocPtr, std::string schema); + bool validateXMLData(std::string data, std::string schema); bool validateXMLFile(std::string filename, std::string schema); // specific parsing functions @@ -106,7 +106,6 @@ namespace fragrant XMLS_Source parseSpriteSource(xmlNode* top); XMLS_Sprite parseSpriteSprite(xmlNode* top); - std::vector parseSpriteItems(xmlNode* top); std::vector parseSpriteFrames(xmlNode* top); // setting the RelaxNG search root -- 2.11.4.GIT