void RenderComponent::UpdateFromXML(pugi::xml_node node) { std::cout << sprite.getName() << std::endl; std::cout << GetXMLData(node, "Sprite name").as_string() << std::endl; if(sprite.getName().compare(GetXMLData(node, "Sprite name").as_string())) { std::cout << "change please" << std::endl; sprite = ResourceManager::GetInstance()->GetSprite(GetXMLData(node, "Sprite name").as_string()); } animationRect = sf::Rect<int>(GetXMLData(node, "Rectangle X").as_int(), GetXMLData(node, "Rectangle Y").as_int(), GetXMLData(node, "Rectangle Width").as_int(), GetXMLData(node, "Rectangle Height").as_int()); }
/** * This will loop through the file and extract XML Data. * @param _fileName the path to the file which will be read */ int XMLReader(string _fileName) { ifstream infile; // Input file stream for XML file to parse int intLineCount = 0; // Keep track of line number string strLine = ""; // Hold current line while parsing XML file vector<Element*> vecElementStack; // Will hold all tag names and tag lines string previousElementName = ""; // The tag name of the previous element on the vector (stack) ParserState currentState = STARTING_DOCUMENT; // Will hold state of previously read line Element* rootElement = NULL; infile.open(_fileName, ifstream::in); if ( infile.fail() ) { cerr << "Error opening '" << _fileName << "'" << endl ; return EXIT_FAILURE; } else { // Loop through the file do { // Increment line counter intLineCount++; // Read a new line from the file getline(infile, strLine); // Get tag name of previous open tag element (will return "" if none) previousElementName = getLastElement(vecElementStack); // Get state of newly read line currentState = GetXMLData(strLine, currentState); // Handle parser state specific actions if (currentState == ELEMENT_OPENING_TAG) //########################## HERE { Element* tempElement = new Element(intLineCount, strLine, vecElementStack.size(), currentState); tempElement->addAttribute(getAttributes(strLine)); if (rootElement == NULL) // First time adding to the tree { rootElement = tempElement; } else { (vecElementStack[ vecElementStack.size() - 1 ])->addChild( tempElement ); } vecElementStack.push_back(tempElement); previousElementName = getLastElement(vecElementStack); } else if (currentState == ELEMENT_CLOSING_TAG) { if (previousElementName != getClosingTagName(strLine)) { // if open tag name != closing tag name cout << endl << "*******************************************" << endl; cout << "ERROR: Invalid closing tag at Line " << intLineCount << endl; cout << "REASON: " << previousElementName << " != " << getClosingTagName(strLine) << endl; cout << "ABORTING..." << endl; cout << "*******************************************" << endl; return EXIT_FAILURE; } vecElementStack.pop_back(); } else if (currentState == ELEMENT_NAME_AND_CONTENT) { Element* tempElement = new Element(intLineCount, strLine, vecElementStack.size(), currentState); tempElement->addAttribute(getAttributes(strLine)); (vecElementStack[ vecElementStack.size() - 1 ])->addChild( tempElement ); } else if (currentState == ERROR) { removeWhiteSpace(strLine); cout << endl << "*******************************************" << endl; cout << "ERROR: Something went wrong!" << endl; cout << "~~ Line " << intLineCount << ": " << strLine << endl; cout << "ABORTING..." << endl; cout << "*******************************************" << endl; return EXIT_FAILURE; } printXMLData(vecElementStack, currentState, intLineCount, strLine, previousElementName); cout << endl; } while (infile.good()); cout << endl << endl << endl << "TREE OUTPUT" << endl; cout << "********************************************************" << endl; RecursivePrint(rootElement); deleteVectorData(vecElementStack); } }