void Parameters::readFile(string str){ file = str; XMLPlatformUtils::Initialize(); XercesDOMParser parser; parser.setValidationScheme(XercesDOMParser::Val_Always); HandlerBase errHandler;// = (ErrorHandler*) new HandlerBase(); parser.setErrorHandler(&errHandler); parser.parse(str.c_str()); DOMDocument * doc = parser.getDocument(); DOMElement* elementRoot = doc->getDocumentElement(); // Extract floats DOMElement* floatRoot = (DOMElement *) elementRoot->getElementsByTagName(XMLString::transcode("real"))->item(0); DOMElement* child = floatRoot->getFirstElementChild(); do{ saveReal(XMLString::transcode(child->getNodeName()), atof(XMLString::transcode(child->getTextContent()))); child = child->getNextElementSibling(); }while(child != NULL); // Extract integers DOMElement* intRoot = (DOMElement *) elementRoot->getElementsByTagName(XMLString::transcode("integer"))->item(0); child = intRoot->getFirstElementChild(); do{ saveInteger( XMLString::transcode(child->getNodeName()), atoi(XMLString::transcode(child->getTextContent()))); child = child->getNextElementSibling(); }while(child != NULL); }
void XmlSchemaGenerator::findAllElements ( const DOMElement &element, size_t nIndent /*= 0*/) { wxString tagName = WrapXerces::toString ( element.getTagName() ); mElements[tagName].nodes.insert ( &element ); DOMElement *child = element.getFirstElementChild(); for ( ; child != NULL; child = child->getNextElementSibling() ) { findAllElements ( *child, nIndent ); } }
void XmlSchemaGenerator::generateData ( const DOMElement &element, size_t nIndent /*= 0*/) { wxString name = WrapXerces::toString ( element.getTagName() ); if ( mElements[name].name.empty() ) { // Only generate data once generateData ( name, nIndent ); } DOMElement *child = element.getFirstElementChild(); for ( ; child != NULL; child = child->getNextElementSibling() ) { generateData ( *child, nIndent ); } }
void XmlSchemaGenerator::outputSchema ( const DOMElement &element ) { wxString tagName = WrapXerces::toString ( element.getTagName() ); ElmtData &data = mElements[tagName]; if ( data.schema.empty() ) { if ( mGrammarType == Grammar::SchemaGrammarType ) generateSchema ( data, 1 ); else generateDTD ( data, 1 ); mSchema << data.schema; } DOMElement *child = element.getFirstElementChild(); for ( ; child != NULL; child = child->getNextElementSibling() ) { outputSchema ( *child ); } }
XERCES_CPP_NAMESPACE_USE std::vector<DgFileTile> DgFileTile::getTiles(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDocument, const std::string& filename, unsigned int& height, unsigned int& width) { std::vector<DgFileTile> tiles; DOMElement* pRoot = pDocument->getDocumentElement(); if (pRoot == NULL || !XMLString::equals(pRoot->getNodeName(), X("isd"))) { return tiles; } DOMNodeList* pTilList = pRoot->getElementsByTagName(X("TIL")); if (pTilList == NULL || pTilList->getLength() != 1) { return tiles; } DOMNode* pTil = pTilList->item(0); if (pTil == NULL || pTil->getNodeType() != DOMNode::ELEMENT_NODE) { return tiles; } DOMElement* pTilElement = static_cast<DOMElement*>(pTil); DOMNodeList* pTilesList = pTilElement->getElementsByTagName(X("TILE")); if (pTilesList == NULL) { return tiles; } height = 0; width = 0; bool error = false; QFileInfo fileInfo(QString::fromStdString(filename)); QDir fileDir = fileInfo.dir(); for (unsigned int i = 0; i < pTilesList->getLength(); ++i) { DgFileTile curTile; DOMNode* pNode = pTilesList->item(i); if (pNode == NULL || pNode->getNodeType() != DOMNode::ELEMENT_NODE) { continue; } DOMElement* pElement = static_cast<DOMElement*>(pNode); DOMElement* pChildElement = pElement->getFirstElementChild(); while (pChildElement != NULL) { std::string textContent = A(pChildElement->getTextContent()); if (XMLString::equals(pChildElement->getNodeName(), X("FILENAME"))) { curTile.mTilFilename = fileDir.filePath(QString::fromStdString(textContent)).toStdString(); } if (XMLString::equals(pChildElement->getNodeName(), X("ULCOLOFFSET"))) { curTile.mStartCol = StringUtilities::fromXmlString<unsigned int>(textContent, &error); } if (XMLString::equals(pChildElement->getNodeName(), X("ULROWOFFSET"))) { curTile.mStartRow = StringUtilities::fromXmlString<unsigned int>(textContent, &error); } if (XMLString::equals(pChildElement->getNodeName(), X("LRCOLOFFSET"))) { curTile.mEndCol = StringUtilities::fromXmlString<unsigned int>(textContent, &error); } if (XMLString::equals(pChildElement->getNodeName(), X("LRROWOFFSET"))) { curTile.mEndRow = StringUtilities::fromXmlString<unsigned int>(textContent, &error); } pChildElement = pChildElement->getNextElementSibling(); } tiles.push_back(curTile); if (curTile.mEndCol > width) { width = curTile.mEndCol; } if (curTile.mEndRow > height) { height = curTile.mEndRow; } } return tiles; }