bool XMLParser::Parse() { while (xmlTextReaderRead(inputReader) == 1) { const int type = xmlTextReaderNodeType(inputReader); // 1 is Element if (type != 1) { continue; } xmlChar *currentName = xmlTextReaderName(inputReader); if (currentName == nullptr) { continue; } if (xmlStrEqual(currentName, (const xmlChar *)"node") == 1) { ImportNode current_node = ReadXMLNode(); ParseNodeInLua(current_node, lua_state); extractor_callbacks->ProcessNode(current_node); } if (xmlStrEqual(currentName, (const xmlChar *)"way") == 1) { ExtractionWay way = ReadXMLWay(); ParseWayInLua(way, lua_state); extractor_callbacks->ProcessWay(way); } if (use_turn_restrictions && xmlStrEqual(currentName, (const xmlChar *)"relation") == 1) { InputRestrictionContainer current_restriction = ReadXMLRestriction(); if ((UINT_MAX != current_restriction.fromWay) && !extractor_callbacks->ProcessRestriction(current_restriction)) { std::cerr << "[XMLParser] restriction not parsed" << std::endl; } } xmlFree(currentName); } return true; }
CXMLNode *CXMLParser::RarseFile(char *cText) { if(!cText) { return NULL; } if(!cText[0]) { return NULL; } int nLen = strlen(cText); LinePreProcess(cText, nLen); #ifdef FN_USE_SDRAM2 CXMLNode *pHead = (CXMLNode *)FN_alloc(SDRAM2, NODE_LEN, 8); #else CXMLNode *pHead = (CXMLNode*)malloc(NODE_LEN); #endif if(!pHead) { printf("mem alloc fail\r\n"); return NULL; } memset(pHead, 0, sizeof(CXMLNode)); char *pRet = RemoveXMLDeclare(cText); if(pRet) { cText = pRet; } int nRet = 0; m_cText = cText; nRet = ReadXMLNode(pHead); if(nRet < 0) { printf("analyse fail\r\n"); //清除结点树 ClearNodeTree(pHead); return NULL; } return pHead; }