DOMElement *NclImportParser::parseImportedDocumentBase( DOMElement *parentElement ) { DOMNodeList *elementNodeList; DOMElement *element; DOMNode *node; string elementTagName; //pre-compile attributes if (parentElement == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); for (int i = 0; i < (int) elementNodeList->getLength(); i++) { node = elementNodeList->item( i ); if (node->getNodeType() == DOMNode::ELEMENT_NODE) { element = (DOMElement*) node; elementTagName = getXmlHandler()->getStr( element->getTagName() ); if (elementTagName.compare( "importNCL" ) == 0) { if (!addImportNCLToImportedDocumentBase(element)){ return NULL; } } } } return parentElement; }
/* Iterative tree-walker. When you have a Parent link, there's often no need to resort to recursion. NOTE THAT only Element nodes are matched since we're specifically supporting getElementsByTagName(). */ DOMNode *DOMDeepNodeListImpl::nextMatchingElementAfter(DOMNode *current) { DOMNode *next; while (current != 0) { // Look down to first child. if (current->hasChildNodes()) { current = current->getFirstChild(); } // Look right to sibling (but not from root!) else { if (current != fRootNode && 0 != (next = current->getNextSibling())) { current = next; } // Look up and right (but not past root!) else { next = 0; for (; current != fRootNode; // Stop on return to starting point current = current->getParentNode()) { next = current->getNextSibling(); if (next != 0) break; } current = next; } } // Have we found an Element with the right tagName? // ("*" matches anything.) if (current != 0 && current != fRootNode && current->getNodeType() == DOMNode::ELEMENT_NODE) { DOMElement *currElement = (DOMElement *)current; if (!fMatchURIandTagname) { //DOM Level 1 if (fMatchAll || XMLString::equals(currElement->getTagName(), fTagName)) return current; } else { //DOM Level 2 if (!fMatchAllURI && !XMLString::equals(current->getNamespaceURI(), fNamespaceURI)) continue; if (fMatchAll || XMLString::equals(current->getLocalName(), fTagName)) return current; } } // Otherwise continue walking the tree } // Fell out of tree-walk; no more instances found return 0; }
void *NclPresentationControlParser::parseRuleBase( DOMElement *parentElement, void *objGrandParent) { wclog << "parseRuleBase" << endl; void *parentObject; DOMNodeList *elementNodeList; DOMElement *element; DOMNode *node; string elementTagName; void *elementObject; parentObject = createRuleBase(parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); for (int i = 0; i < (int)elementNodeList->getLength(); i++) { node = elementNodeList->item(i); if (node->getNodeType() == DOMNode::ELEMENT_NODE) { element = (DOMElement*)node; elementTagName = XMLString::transcode(element->getTagName()); wclog << ">>" << elementTagName.c_str() << ": "; wclog << XMLString::transcode(element->getAttribute(XMLString::transcode("id"))) << endl; if (XMLString::compareIString(elementTagName.c_str(), "importBase") == 0) { elementObject = getImportParser()->parseImportBase( element, parentObject); if (elementObject != NULL) { addImportBaseToRuleBase(parentObject, elementObject); } } else if(XMLString::compareIString(elementTagName.c_str(), "rule") == 0) { elementObject = parseRule(element, parentObject); if (elementObject != NULL) { addRuleToRuleBase(parentObject, elementObject); } } else if(XMLString::compareIString(elementTagName.c_str(), "compositeRule")==0) { elementObject = parseCompositeRule(element, parentObject); if (elementObject != NULL) { addCompositeRuleToRuleBase(parentObject, elementObject); } } } } return parentObject; }
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 ); } }
DOMElement DOMElement::getChildNode(const char * tagname) { NodeList nodes = getChildNodes(); for(NodeList::iterator it = nodes.begin(); it != nodes.end(); it++) { DOMElement e = *it; if(e.getTagName() == tagname) return e; } return DOMElement(0); }
void *NclConnectorsParser::parseCompoundStatement( DOMElement *parentElement, void *objGrandParent) { wclog << "parseCompoundStatement" << endl; void *parentObject = NULL; DOMNodeList *elementNodeList; DOMElement *element; DOMNode *node; string elementTagName = ""; void *elementObject = NULL; parentObject = createCompoundStatement(parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); for (int i = 0; i < (int)elementNodeList->getLength(); i++) { node = elementNodeList->item(i); if(node->getNodeType()==DOMNode::ELEMENT_NODE){ element = (DOMElement*)node; elementTagName = XMLString::transcode( element->getTagName() ); wclog << ">>" << elementTagName.c_str() << ": "; wclog << XMLString::transcode(element->getAttribute(XMLString::transcode("id"))) << endl; if (XMLString::compareIString(elementTagName.c_str(), "assessmentStatement") == 0) { elementObject = parseAssessmentStatement( element, parentObject); if (elementObject != NULL) { addAssessmentStatementToCompoundStatement( parentObject, elementObject); } } else if (XMLString::compareIString(elementTagName.c_str(), "compoundStatement") == 0) { elementObject = parseCompoundStatement( element, parentObject); if (elementObject != NULL) { addCompoundStatementToCompoundStatement( parentObject, elementObject); } } } } return parentObject; }
OGRPolygon *getPolygon(DOMElement *elem) { OGRPolygon *pg = new OGRPolygon(); DOMElement *boundaryElem = (DOMElement *)elem->getFirstChild(); // outer boundary while (boundaryElem != NULL) { char* pszTagName = XMLString::transcode(boundaryElem->getTagName()); if (cmpStr(ILI2_BOUNDARY, pszTagName) == 0) pg->addRingDirectly(getBoundary(boundaryElem)); XMLString::release(&pszTagName); boundaryElem = (DOMElement *)boundaryElem->getNextSibling(); // inner boundaries } return pg; }
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* NclTransitionParser::parseTransitionBase( DOMElement* parentElement, void* objGrandParent) { wclog << "parseTransitionBase" << endl; void *parentObject; DOMNodeList *elementNodeList; DOMElement *element; DOMNode *node; string elementTagName; void *elementObject; parentObject = createTransitionBase(parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); for (int i = 0; i < (int)elementNodeList->getLength(); i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE) { element = (DOMElement*)node; elementTagName = XMLString::transcode(element->getTagName()); if (XMLString::compareIString( elementTagName.c_str(), "importBase") == 0) { elementObject = getImportParser()->parseImportBase( element, parentObject); if (elementObject != NULL) { addImportBaseToTransitionBase( parentObject, elementObject); } } else if (XMLString::compareIString( elementTagName.c_str(), "transition") == 0) { elementObject = parseTransition(element, parentObject); if (elementObject != NULL) { addTransitionToTransitionBase( parentObject, elementObject); } } } } return parentObject; }
OGRLinearRing *getBoundary(DOMElement *elem) { DOMElement *lineElem = (DOMElement *)elem->getFirstChild(); if (lineElem != NULL) { char* pszTagName = XMLString::transcode(lineElem->getTagName()); if (cmpStr(ILI2_POLYLINE, pszTagName) == 0) { XMLString::release(&pszTagName); return (OGRLinearRing*) getLineString(lineElem, TRUE); } XMLString::release(&pszTagName); } return new OGRLinearRing(); }
static OGRCompoundCurve *getBoundary(DOMElement *elem) { DOMElement *lineElem = (DOMElement *)elem->getFirstChild(); if (lineElem != NULL) { char* pszTagName = XMLString::transcode(lineElem->getTagName()); if (cmpStr(ILI2_POLYLINE, pszTagName) == 0) { XMLString::release(&pszTagName); return getPolyline(lineElem); } XMLString::release(&pszTagName); } return new OGRCompoundCurve(); }
//============================================================================= // METHOD: SPELLxmlConfigReaderXC::findElementsByName //============================================================================= SPELLxmlNodeList SPELLxmlConfigReaderXC::findElementsByName( std::string tagName ) { SPELLxmlNodeList result; if (m_document == NULL) { THROW_EXCEPTION("Cannot find elements", "No document available", SPELL_ERROR_CONFIG); } DEBUG("[CFGR] Get elements by name: " + tagName); // Get the tag translation XMLCh* tag = XMLString::transcode(tagName.c_str()); // Get the top-level element DOMElement* elementRoot = m_document->getDocumentElement(); if( !elementRoot ) { THROW_EXCEPTION("Cannot get root element", "Empty document", SPELL_ERROR_CONFIG); } DOMNodeList* children = elementRoot->getChildNodes(); const XMLSize_t nodeCount = children->getLength(); // For all nodes, children of "root" in the XML tree. for (XMLSize_t xx = 0; xx < nodeCount; ++xx) { DOMNode* currentNode = children->item(xx); if (currentNode->getNodeType() && // true is not NULL currentNode->getNodeType() == DOMNode::ELEMENT_NODE) // is element { // Found node which is an Element. Re-cast node as element DOMElement* currentElement = dynamic_cast<xercesc::DOMElement*> (currentNode); if (XMLString::equals(currentElement->getTagName(), tag)) { result.push_back( convertToNode( currentElement ) ); } } } XMLString::release(&tag); DEBUG("[CFGR] Found " + ISTR(result.size()) + " elements"); return result; }
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 ); } }
OGRCircularString *ILI2Reader::getArc(DOMElement *elem) { // elem -> ARC OGRCircularString *arc = new OGRCircularString(); // previous point -> start point OGRPoint *ptStart = getPoint((DOMElement *)elem->getPreviousSibling()); // COORD or ARC // end point OGRPoint *ptEnd = new OGRPoint(); // point on the arc OGRPoint *ptOnArc = new OGRPoint(); // double radius = 0; // radius DOMElement *arcElem = (DOMElement *)elem->getFirstChild(); while (arcElem != NULL) { char* pszTagName = XMLString::transcode(arcElem->getTagName()); char* pszObjValue = getObjValue(arcElem); if (cmpStr("C1", pszTagName) == 0) ptEnd->setX(CPLAtof(pszObjValue)); else if (cmpStr("C2", pszTagName) == 0) ptEnd->setY(CPLAtof(pszObjValue)); else if (cmpStr("C3", pszTagName) == 0) ptEnd->setZ(CPLAtof(pszObjValue)); else if (cmpStr("A1", pszTagName) == 0) ptOnArc->setX(CPLAtof(pszObjValue)); else if (cmpStr("A2", pszTagName) == 0) ptOnArc->setY(CPLAtof(pszObjValue)); else if (cmpStr("A3", pszTagName) == 0) ptOnArc->setZ(CPLAtof(pszObjValue)); else if (cmpStr("R", pszTagName) == 0) { // radius = CPLAtof(pszObjValue); } CPLFree(pszObjValue); XMLString::release(&pszTagName); arcElem = (DOMElement *)arcElem->getNextSibling(); } arc->addPoint(ptStart); arc->addPoint(ptOnArc); arc->addPoint(ptEnd); delete ptStart; delete ptOnArc; delete ptEnd; return arc; }
void PEPConfig::parseListenerServiceConfig(DOMElement* elemListener) { const DOMNodeList * children = elemListener->getChildNodes(); for (XMLSize_t idx = 0; idx < children->getLength(); ++idx) { DOMNode* currentNode = children->item(idx); if (currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE) { // is element DOMElement* currentElement = dynamic_cast<xercesc::DOMElement*>(currentNode); const XMLCh * xmlch_elementName = currentElement->getTagName(); char * elementName = XMLString::transcode(xmlch_elementName); map<string, ListenerServiceFactory>::iterator it_res = m_ListenerFactoryMap.find( string(elementName)); if (it_res != m_ListenerFactoryMap.end()) { ListenerServiceFactory factory = (*it_res).second; m_PEPInstance->setListenerServiceFactory(factory, currentElement); } } } }
void MgResourceDefinitionManager::ValidateDocument(XmlDocument& xmlDoc) { MG_RESOURCE_SERVICE_TRY() MgResourceIdentifier resource(MgUtil::MultiByteToWideChar(xmlDoc.getName())); // Skip XML schema validation on runtime resources. if (!resource.IsRuntimeResource()) { std::string xmlContent; MgXmlUtil xmlUtil(xmlDoc.getContent(xmlContent)); DOMElement* rootNode = xmlUtil.GetRootNode(); if(NULL != rootNode) { assert(NULL != rootNode); STRING rootName; const XMLCh* tag = rootNode->getTagName(); if (NULL != tag) { rootName = X2W(tag); assert(!rootName.empty()); } STRING schemaName; const XMLCh* attr = rootNode->getAttribute(X("xsi:noNamespaceSchemaLocation")); if (NULL != attr) { schemaName = X2W(attr); } ValidateDocument(resource, rootName, schemaName); } } MG_RESOURCE_CONTAINER_CATCH_AND_THROW(L"MgResourceDefinitionManager.ValidateDocument") }
OGRLineString *ILI2Reader::getArc(DOMElement *elem) { // elem -> ARC OGRLineString *ls = new OGRLineString(); // previous point -> start point OGRPoint *ptStart = getPoint((DOMElement *)elem->getPreviousSibling()); // COORD or ARC // end point OGRPoint *ptEnd = new OGRPoint(); // point on the arc OGRPoint *ptOnArc = new OGRPoint(); double radius = 0; // radius DOMElement *arcElem = (DOMElement *)elem->getFirstChild(); while (arcElem != NULL) { char* pszTagName = XMLString::transcode(arcElem->getTagName()); char* pszObjValue = getObjValue(arcElem); if (cmpStr("C1", pszTagName) == 0) ptEnd->setX(atof(pszObjValue)); else if (cmpStr("C2", pszTagName) == 0) ptEnd->setY(atof(pszObjValue)); else if (cmpStr("C3", pszTagName) == 0) ptEnd->setZ(atof(pszObjValue)); else if (cmpStr("A1", pszTagName) == 0) ptOnArc->setX(atof(pszObjValue)); else if (cmpStr("A2", pszTagName) == 0) ptOnArc->setY(atof(pszObjValue)); else if (cmpStr("A3", pszTagName) == 0) ptOnArc->setZ(atof(pszObjValue)); else if (cmpStr("R", pszTagName) == 0) radius = atof(pszObjValue); CPLFree(pszObjValue); XMLString::release(&pszTagName); arcElem = (DOMElement *)arcElem->getNextSibling(); } ptEnd->flattenTo2D(); ptOnArc->flattenTo2D(); interpolateArc(ls, ptStart, ptOnArc, ptEnd, arcIncr); delete ptStart; delete ptOnArc; delete ptEnd; return ls; }
OGRPoint *getPoint(DOMElement *elem) { // elem -> COORD (or ARC) OGRPoint *pt = new OGRPoint(); DOMElement *coordElem = (DOMElement *)elem->getFirstChild(); while (coordElem != NULL) { char* pszTagName = XMLString::transcode(coordElem->getTagName()); char* pszObjValue = getObjValue(coordElem); if (cmpStr("C1", pszTagName) == 0) pt->setX(atof(pszObjValue)); else if (cmpStr("C2", pszTagName) == 0) pt->setY(atof(pszObjValue)); else if (cmpStr("C3", pszTagName) == 0) pt->setZ(atof(pszObjValue)); CPLFree(pszObjValue); XMLString::release(&pszTagName); coordElem = (DOMElement *)coordElem->getNextSibling(); } pt->flattenTo2D(); return pt; }
void *NclImportParser::parseImportedDocumentBase( DOMElement *parentElement, void *objGrandParent) { void *parentObject; DOMNodeList *elementNodeList; DOMElement *element; DOMNode *node; string elementTagName; void *elementObject; //pre-compile attributes parentObject = createImportedDocumentBase( parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); for (int i = 0; i < (int)elementNodeList->getLength(); i++) { node = elementNodeList->item(i); if(node->getNodeType()==DOMNode::ELEMENT_NODE){ element = (DOMElement*)node; elementTagName = XMLString::transcode( element->getTagName() ); if (XMLString::compareIString( elementTagName.c_str(), "importNCL") == 0) { elementObject = parseImportNCL(element, parentObject); if (elementObject != NULL) { addImportNCLToImportedDocumentBase( parentObject, elementObject); } } } } return parentObject; }
void *NclLayoutParser::parseRegion( DOMElement *parentElement, void *objGrandParent) { wclog << "parseRegion" << endl; void *parentObject; DOMNodeList *elementNodeList; DOMElement *element; DOMNode *node; string elementTagName; void *elementObject; parentObject = createRegion(parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); for (int i = 0; i < (int)elementNodeList->getLength(); i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE) { element = (DOMElement*)node; elementTagName = XMLString::transcode(element->getTagName()); wclog << ">>" << elementTagName.c_str() << ": "; wclog << XMLString::transcode(element->getAttribute(XMLString::transcode("id"))); if (XMLString::compareIString( elementTagName.c_str(), "region") == 0) { elementObject = parseRegion(element, parentObject); if (elementObject != NULL) { addRegionToRegion(parentObject, elementObject); } } } } return parentObject; }
void PEPConfig::initialize(string& configFile) throw (std::runtime_error) { Lock initLock(m_lock); if (m_initCount == INT_MAX) { Category::getInstance("PEPConfig").crit("library initialized too many times"); return; } if (m_initCount >= 1) { ++m_initCount; return; } const char* logconf = getenv("SHIBSP_LOGGING"); string logpath = configFile.substr(0, configFile.find_last_of('/')); if (!logconf || !*logconf) { if (isEnabled(PEPConfig::OutOfProcess) && !isEnabled(PEPConfig::InProcess)) logconf = logpath.append("/pepd.logger").c_str(); else if (isEnabled(PEPConfig::InProcess) && !isEnabled(PEPConfig::OutOfProcess)) logconf = logpath.append("/mod_pep.logger").c_str(); else logconf = logpath.append("/pepd.logger").c_str(); } XMLToolingConfig::getConfig().log_config(logconf); Category& log = Category::getInstance("Config"); log.debug("library initialization started"); XMLToolingConfig::getConfig().user_agent = string("PEP"); if (!XMLToolingConfig::getConfig().init()) { log.fatal("failed to initialize XMLTooling library"); throw(std::runtime_error("failed to initialize XMLTooling library")); } if (m_PEPInstance) { delete m_PEPInstance; } m_PEPInstance = new PEP(); statConfigFile(configFile); // register listener service factories registerListenerServices(); // Configure DOM parser. m_ConfigFileParser->setValidationScheme(XercesDOMParser::Val_Never); m_ConfigFileParser->setDoNamespaces(false); m_ConfigFileParser->setDoSchema(false); m_ConfigFileParser->setLoadExternalDTD(false); try { m_ConfigFileParser->parse(configFile.c_str()); // no need to free this pointer - owned by the parent parser object DOMDocument* xmlDoc = m_ConfigFileParser->getDocument(); // Get the top-level element: NAme is "root". No attributes for "root" DOMElement* elementRoot = xmlDoc->getDocumentElement(); if (!elementRoot) throw(std::runtime_error("empty XML document")); // Parse XML file for tags of interest: "ApplicationSettings" // Look one level nested within "root". (child of root) DOMNodeList* children = elementRoot->getChildNodes(); const XMLSize_t nodeCount = children->getLength(); // For all nodes, children of "root" in the XML tree. for (XMLSize_t xx = 0; xx < nodeCount; ++xx) { DOMNode* currentNode = children->item(xx); if (currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE) { // is element // Found node which is an Element. Re-cast node as element DOMElement* currentElement = dynamic_cast<xercesc::DOMElement*>(currentNode); if (XMLString::equals(currentElement->getTagName(), APPLICATION_DEFAULTS_ELEM)) { parseApplicationConfig(currentElement); } else if (XMLString::equals(currentElement->getTagName(), LISTENER_ELEM)) { parseListenerServiceConfig(currentElement); } } } } catch (xercesc::XMLException& e) { char* message = xercesc::XMLString::transcode(e.getMessage()); ostringstream errBuf; errBuf << "Error parsing file: " << message << flush; XMLString::release(&message); } ++m_initCount; }
//initialize a ResultXML object using an existing xml file ResultXML::ResultXML(const char *file) { //sets-up for XML processing and handle any errors if unsuccessful try{ XMLPlatformUtils::Initialize(); } catch (XMLException &e){ char *msg = XMLString::transcode(e.getMessage()); XERCES_STD_QUALIFIER cerr << "Error During Initialization: " << endl << msg; XMLString::release(&msg); } catch (...){ cerr << "Error Unknown Exception Encountered!" << endl; } //create a parser and set it to validate document but not load a DTD or use a schema XercesDOMParser *parser = new XercesDOMParser(); parser->setValidationScheme(XercesDOMParser::Val_Always); parser->setDoSchema(false); parser->setLoadExternalDTD(false); try{ //create unicode strings to for later use XMLCh *spdName = XMLString::transcode("speed_result"); XMLCh *memName = XMLString::transcode("memory_result"); XMLCh *sectName = XMLString::transcode("section_list"); XMLCh *fname = XMLString::transcode(file); //set the save location, parse the file and retrieve the required nodes ftarget = new LocalFileFormatTarget(fname); parser->parse(file); doc = parser->getDocument(); root = doc->getDocumentElement(); DOMNodeList *nlist = root->getChildNodes(); //go through the nodelist finding the top level child nodes and assign them to the right member variables for(XMLSize_t i=0; i<nlist->getLength(); i++){ DOMNode *curNode = nlist->item(i); DOMElement *curElm; //safely check for element node before casting if(curNode->getNodeType() == DOMNode::ELEMENT_NODE){ curElm = dynamic_cast<DOMElement*>(curNode); } //check the tag name and assign accordingly if(XMLString::equals(spdName, curElm->getTagName())){ spdResult = curElm; } else if(XMLString::equals(memName, curElm->getTagName())){ memResult = curElm; } else if(XMLString::equals(sectName, curElm->getTagName())){ sectList = curElm; } } //release the memory occupied by the encoded strings XMLString::release(&spdName); XMLString::release(&memName); XMLString::release(§Name); XMLString::release(&fname); } catch (const OutOfMemoryException&){ XERCES_STD_QUALIFIER cerr << "Error Out of Memory Exception: " << XERCES_STD_QUALIFIER endl; } catch (const DOMException& e){ XERCES_STD_QUALIFIER cerr << "Error DOMException Encountered Code: " << e.code << XERCES_STD_QUALIFIER endl; } catch (...){ XERCES_STD_QUALIFIER cerr << "Unknown Error Encountered, Could Not Create Document" << XERCES_STD_QUALIFIER endl; } delete parser; }
OGRGeometry *ILI2Reader::getGeometry(DOMElement *elem, int type) { OGRGeometryCollection *gm = new OGRGeometryCollection(); DOMElement *childElem = elem; while (childElem != NULL) { char* pszTagName = XMLString::transcode(childElem->getTagName()); switch (type) { case ILI2_COORD_TYPE : if (cmpStr(ILI2_COORD, pszTagName) == 0) { delete gm; XMLString::release(&pszTagName); return getPoint(childElem); } break; case ILI2_ARC_TYPE : // is it possible here? It have to be a ARC or COORD before (getPreviousSibling) if (cmpStr(ILI2_ARC, pszTagName) == 0) { delete gm; XMLString::release(&pszTagName); return getArc(childElem); } break; case ILI2_POLYLINE_TYPE : if (cmpStr(ILI2_POLYLINE, pszTagName) == 0) { delete gm; XMLString::release(&pszTagName); return getLineString(childElem, FALSE); } break; case ILI2_BOUNDARY_TYPE : if (cmpStr(ILI2_BOUNDARY, pszTagName) == 0) { delete gm; XMLString::release(&pszTagName); return getLineString(childElem, FALSE); } break; case ILI2_AREA_TYPE : if ((cmpStr(ILI2_AREA, pszTagName) == 0) || (cmpStr(ILI2_SURFACE, pszTagName) == 0)) { delete gm; XMLString::release(&pszTagName); return getPolygon(childElem); } break; default : if (type >= ILI2_GEOMCOLL_TYPE) { int subType = getGeometryTypeOfElem(childElem); //???? gm->addGeometryDirectly(getGeometry(childElem, subType)); } break; } XMLString::release(&pszTagName); // GEOMCOLL childElem = (DOMElement *)childElem->getNextSibling(); } return gm; }
int main( ) { try { // Initialize Xerces and retrieve a DOMImplementation; // specify that you want to use the Load and Save (LS) // feature XercesInitializer init; DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation( fromNative("LS").c_str( ) ); if (impl == 0) { cout << "couldn't create DOM implementation\n"; return EXIT_FAILURE; } // Construct a DOMBuilder to parse animals.xml. DOMPtr<DOMBuilder> parser = static_cast<DOMImplementationLS*>(impl)-> createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0); // Enable namespaces (not needed in this example) parser->setFeature(XMLUni::fgDOMNamespaces, true); // Register an error handler CircusErrorHandler err; parser->setErrorHandler(&err); // Parse animals.xml; you can use a URL here // instead of a file name DOMDocument* doc = parser->parseURI("animals.xml"); // Search for Herby the elephant: first, obtain a pointer // to the "animalList" element. DOMElement* animalList = doc->getDocumentElement( ); if (animalList->getTagName( ) != fromNative("animalList")) { cout << "bad document root: " << toNative(animalList->getTagName( )) << "\n"; return EXIT_FAILURE; } // Next, iterate through the "animal" elements, searching // for Herby the elephant. DOMNodeList* animals = animalList->getElementsByTagName(fromNative("animal").c_str( )); for ( size_t i = 0, len = animals->getLength( ); i < len; ++i ) { DOMElement* animal = static_cast<DOMElement*>(animals->item(i)); const XMLCh* name = getAnimalName(animal); if (name != 0 && name == fromNative("Herby")) { // Found Herby -- remove him from document. animalList->removeChild(animal); animal->release( ); // optional. break; } } // Construct a DOMWriter to save animals.xml. DOMPtr<DOMWriter> writer = static_cast<DOMImplementationLS*>(impl)->createDOMWriter( ); writer->setErrorHandler(&err); // Save animals.xml. LocalFileFormatTarget file("animals.xml"); writer->writeNode(&file, *animalList); } catch (const SAXException& e) { cout << "xml error: " << toNative(e.getMessage( )) << "\n"; return EXIT_FAILURE; } catch (const DOMException& e) { cout << "xml error: " << toNative(e.getMessage( )) << "\n"; return EXIT_FAILURE; } catch (const exception& e) { cout << e.what( ) << "\n"; return EXIT_FAILURE; } }
//=================================================================================================================== void geometryLoader::acquireInfo(DOMElement * element) { // static const boost::regex matchDoubleQuotes(".*?\"(.*)\".*", boost::regex::perl); DOMNodeList* children = element->getChildNodes(); const XMLSize_t nodeCount = children->getLength() ; double rowPitch=0,colPitch=0; int dutNumbers=0; std::string parentTagName = XMLString::transcode(element->getTagName()) ; std::map<std::string, std::string> keyValue ; for( XMLSize_t j = 0; j < nodeCount; ++j ) { DOMNode* currentNode = children->item(j); if( !(currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE )) continue ; // is element otherwise close the recursive stack DOMElement * currentElement = dynamic_cast< xercesc::DOMElement* >( currentNode ); // Found node which is an Element. Re-cast node as such. DOMNamedNodeMap * attList = currentNode->getAttributes() ; std::string tagName = XMLString::transcode(currentElement->getTagName()) ; std::string textContent = "" ; std::string textWithBlanks = "" ; if(currentNode->getTextContent()) textWithBlanks = XMLString::transcode(currentElement->getTextContent()) ; textContent = this->stripBlanks(textWithBlanks) ; keyValue.clear() ; bool used = true; for(unsigned int i=0; i<attList->getLength(); ++i) // Set attibutes apart in a temporary hash map { if( attList->item(i)->getTextContent() ) keyValue[ XMLString::transcode(attList->item(i)-> getNodeName())] = this->stripBlanks( XMLString::transcode(attList->item(i)->getTextContent())); } if( tagName == "testBeamGeometry" ) { //theGeometry_-> keyValue["id" ] ; //theGeometry_-> ( this->toLower(keyValue["date"]) ); STDLINE("Entered " + tagName,ACYellow) ; } if( tagName == "stations" ) { ss_.str(""); ss_ << "stations in use: " << keyValue["inUse" ]; STDLINE(ss_.str(),ACYellow) ; } if( tagName == "station" ) { if(this->toLower(keyValue["used"])=="yes") station_ = keyValue["id"]; else used = false ; } if( tagName == "detectors" ) { ss_.str(""); ss_ << "detectors in use: " << keyValue["inUse" ]; STDLINE(ss_.str(),ACYellow) ; } if( tagName == "detector" ) { if( this->toLower(keyValue["used"])=="yes" ) { ss_.str(""); ss_ << "Station: " << station_ << " - " << "Plaq: " << keyValue["id"]; currentPlaqID_ = ss_.str(); theGeometry_->addDetector( currentPlaqID_ ); STDLINE(keyValue["name"] + " detector id: " + currentPlaqID_,ACYellow) ; if( this->toLower(keyValue["isDUT"]) == "yes" ) { theGeometry_->getDetector( currentPlaqID_ )->setDUT(); dutNumbers++; theGeometry_->setDUTnumbers(dutNumbers); } } else used=false; } if( tagName == "largeGranularity" ) { STDLINE("Rotations relative to " + keyValue["relativeRotations"],ACYellow) ; } if( tagName == "xBackFlipped" && this->validContent(tagName,textContent)) { if( this->toLower(textContent) == "yes" || this->toLower(textContent) == "true") { STDLINE("get Detector",ACYellow) ; theGeometry_->getDetector( currentPlaqID_ )->setXBackFlipped(true ); STDLINE("cleared",ACYellow) ; } else theGeometry_->getDetector( currentPlaqID_ )->setXBackFlipped(false); } if( tagName == "yBackFlipped" && this->validContent(tagName,textContent)) { if( this->toLower(textContent) == "yes" || this->toLower(textContent) == "true") theGeometry_->getDetector( currentPlaqID_ )->setYBackFlipped(true ); else theGeometry_->getDetector( currentPlaqID_ )->setYBackFlipped(false); } if( tagName == "xPosition" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXPosition(Utils::toDouble(textContent)*CONVF); if( tagName == "yPosition" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYPosition(Utils::toDouble(textContent)*CONVF); if( tagName == "zPosition" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZPosition(Utils::toDouble(textContent)*CONVF); if( tagName == "xRotation" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXRotation( Utils::toDouble(textContent)); if( tagName == "yRotation" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYRotation( Utils::toDouble(textContent)); if( tagName == "zRotation" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZRotation( Utils::toDouble(textContent) ); if( toRead_ == "correction" || toRead_ == "all" ) { if( tagName == "fineGranularity" ) { STDLINE("Reading fineGranularity",ACGreen); STDLINE("Rotations relative to " + keyValue["relativeRotations"],ACYellow) ; } if( tagName == "xPosCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXPositionCorrection(Utils::toDouble(textContent)*CONVF); if( tagName == "xPositionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXPositionError(Utils::toDouble(textContent)*CONVF); if( tagName == "yPosCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYPositionCorrection(Utils::toDouble(textContent)*CONVF); if( tagName == "yPositionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYPositionError(Utils::toDouble(textContent)*CONVF); if( tagName == "zPosCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZPositionCorrection(Utils::toDouble(textContent)*CONVF); if( tagName == "zPositionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZPositionError(Utils::toDouble(textContent)*CONVF); if( tagName == "xRotationCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXRotationCorrection( Utils::toDouble(textContent) ); if( tagName == "xRotationCorrectionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setXRotationCorrectionError( Utils::toDouble(textContent) ); if( tagName == "yRotationCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYRotationCorrection( Utils::toDouble(textContent) ); if( tagName == "yRotationCorrectionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setYRotationCorrectionError( Utils::toDouble(textContent) ); if( tagName == "zRotationCorrection" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZRotationCorrection( Utils::toDouble(textContent) ); if( tagName == "zRotationCorrectionError" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->setZRotationCorrectionError( Utils::toDouble(textContent) ); } if( tagName == "ROCs" ) { STDLINE("ROCs in use: " + keyValue["inUse"],ACYellow) ; theGeometry_->getDetector( currentPlaqID_ )->setXNumberOfROCs( Utils::toInt(keyValue["xChipsNumber"]) ); theGeometry_->getDetector( currentPlaqID_ )->setYNumberOfROCs( Utils::toInt(keyValue["yChipsNumber"]) ); } if( tagName == "ROC" ) { if( this->toLower(keyValue["used"])=="yes" ) { currentROC_ = Utils::toInt(keyValue["pos"]); theGeometry_->getDetector( currentPlaqID_ )->addROC( Utils::toInt(keyValue["pos"]), Utils::toInt(keyValue["id"] ) ); } else used=false; } if ( tagName == "calibrationFilePath" && this->validContent(tagName,textContent)) theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setCalibrationFilePath(textContent); if ( tagName == "standardRowPitch" && this->validContent(tagName,textContent)) rowPitch = Utils::toDouble(textContent)*CONVF; if ( tagName == "standardColPitch" && this->validContent(tagName,textContent)) { colPitch = Utils::toDouble(textContent)*CONVF; ss_.str(""); ss_ << ACCyan << ACBold << "Pitch. Row : " << ACWhite << ACBold << rowPitch << ACCyan << ACBold << " Col: " << ACWhite << ACBold << colPitch << ACYellow << ACBold << " (tens of microns)"; STDLINE(ss_.str(),ACRed) ; theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setStandardPixPitch(rowPitch,colPitch); } if ( tagName == "nonStandardRowPitch" && this->validContent(tagName,textContent) ) theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOneRowPitch(Utils::toInt(keyValue["rowNum"]), Utils::toDouble(textContent)*CONVF ); if ( tagName == "nonStandardColPitch" && this->validContent(tagName,textContent) ) theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOneColPitch(Utils::toInt(keyValue["colNum"]), Utils::toDouble(textContent)*CONVF ); if( tagName == "MAX_ROWS" && this->validContent(tagName,textContent)) { theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setNumberOfRows(Utils::toInt(textContent)+1 ); } if( tagName == "MAX_COLS" && this->validContent(tagName,textContent)) { theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setNumberOfCols(Utils::toInt(textContent)+1 ); } if( tagName == "orientation" && this->validContent(tagName,textContent)) { theGeometry_->getDetector( currentPlaqID_ )->getROC( currentROC_ )->setOrientation( Utils::toInt(textContent) ); ss_.str("") ; ss_ << ACCyan << ACBold << "Orientation: " << ACWhite << textContent << ACYellow << ACBold << " (degrees)"; STDLINE(ss_.str(),ACGreen) ; } //closingFlag_ = false ; //STDLINE(tagName,ACRed) ; if ( used ) this->acquireInfo(currentElement) ; //STDLINE(tagName,ACGreen) ; //closingFlag_ = true ; } }
OGRLineString *getLineString(DOMElement *elem, int bAsLinearRing) { // elem -> POLYLINE OGRLineString *ls; if (bAsLinearRing) ls = new OGRLinearRing(); else ls = new OGRLineString(); DOMElement *lineElem = (DOMElement *)elem->getFirstChild(); while (lineElem != NULL) { char* pszTagName = XMLString::transcode(lineElem->getTagName()); if (cmpStr(ILI2_COORD, pszTagName) == 0) { OGRPoint* poPoint = getPoint(lineElem); ls->addPoint(poPoint); delete poPoint; } else if (cmpStr(ILI2_ARC, pszTagName) == 0) { // end point OGRPoint *ptEnd = new OGRPoint(); // point on the arc OGRPoint *ptOnArc = new OGRPoint(); // radius double radius = 0; DOMElement *arcElem = (DOMElement *)lineElem->getFirstChild(); while (arcElem != NULL) { char* pszTagName = XMLString::transcode(arcElem->getTagName()); char* pszObjValue = getObjValue(arcElem); if (cmpStr("C1", pszTagName) == 0) ptEnd->setX(atof(pszObjValue)); else if (cmpStr("C2", pszTagName) == 0) ptEnd->setY(atof(pszObjValue)); else if (cmpStr("C3", pszTagName) == 0) ptEnd->setZ(atof(pszObjValue)); else if (cmpStr("A1", pszTagName) == 0) ptOnArc->setX(atof(pszObjValue)); else if (cmpStr("A2", pszTagName) == 0) ptOnArc->setY(atof(pszObjValue)); else if (cmpStr("A3", pszTagName) == 0) ptOnArc->setZ(atof(pszObjValue)); else if (cmpStr("R", pszTagName) == 0) radius = atof(pszObjValue); CPLFree(pszObjValue); XMLString::release(&pszTagName); arcElem = (DOMElement *)arcElem->getNextSibling(); } ptEnd->flattenTo2D(); ptOnArc->flattenTo2D(); OGRPoint *ptStart = getPoint((DOMElement *)lineElem->getPreviousSibling()); // COORD or ARC interpolateArc(ls, ptStart, ptOnArc, ptEnd, PI/180); delete ptStart; delete ptEnd; delete ptOnArc; } /* else { // FIXME StructureValue in Polyline not yet supported } */ XMLString::release(&pszTagName); lineElem = (DOMElement *)lineElem->getNextSibling(); } return ls; }
void XmlSchemaGenerator::generateData ( const wxString &elementName, size_t nIndent /*= 0*/) { ElmtData &data = mElements[elementName]; std::set<const DOMElement *>::iterator elmtItr; data.name = elementName; //Content std::map<wxString, ChildData> &childMap = data.children; std::map<wxString, ChildData>::iterator itr; std::set<wxString> previous; elmtItr = data.nodes.begin(); for ( ; elmtItr != data.nodes.end(); ++elmtItr ) { previous.clear(); std::map<wxString, size_t> countMap; DOMElement *child = ( **elmtItr ).getFirstElementChild(); for ( ; child != NULL; child = child->getNextElementSibling() ) { wxString name = WrapXerces::toString ( child->getTagName() ); childMap[name].prevSiblings.insert ( previous.begin(), previous.end() ); childMap[name].prevSiblings.erase ( name ); // Don't depend on oneself previous.insert ( name ); countMap[name] += 1; } std::map<wxString, size_t>::iterator countItr = countMap.begin(); for ( ; countItr != countMap.end(); ++countItr ) { if ( childMap[countItr->first].maxOccurs < countItr->second ) childMap[countItr->first].maxOccurs = countItr->second; } if ( childMap.size() == countMap.size() ) continue; for ( itr = childMap.begin(); itr != childMap.end(); ++itr ) { if ( countMap.find ( itr->first ) != countMap.end() ) continue; itr->second.minOccurs = 0; } } // Attribute std::map<wxString, const XMLCh *> &attrMap = data.attrMap; std::set<wxString> &optAttrs = data.optAttrs; std::map<wxString, const XMLCh *>::iterator attrItr; elmtItr = data.nodes.begin(); for ( ; elmtItr != data.nodes.end(); ++elmtItr ) { if ( ! ( **elmtItr ).hasAttributes() ) continue; wxString name; DOMAttr *attr; DOMNamedNodeMap *attrs = ( **elmtItr ).getAttributes(); size_t i = attrs->getLength(); while ( i-- > 0 ) { attr = ( DOMAttr* ) attrs->item ( i ); name = WrapXerces::toString ( attr->getName() ); if ( attr->getPrefix() != NULL ) { wxLogDebug ( _T("Ignore: %s"), name.c_str() ); continue; } if ( attr->getSpecified() ) attrMap[name]; // Initialize attribute map else attrMap[name] = attr->getValue(); } if ( attrMap.size() == optAttrs.size() ) continue; for ( attrItr = attrMap.begin(); attrItr != attrMap.end(); ++attrItr ) { if ( attrs->getNamedItem ( ( const XMLCh * ) WrapXerces::toString ( attrItr->first ).GetData() ) == NULL ) { optAttrs.insert ( attrItr->first ); } } } // Deal with sequence wxLogDebug ( _T("%s:"), elementName.c_str() ); data.useSequence = getSequence ( data.sequence, childMap ); // Now we have the data of the element if ( mGrammarType == Grammar::DTDGrammarType ) { generateDTD ( data, nIndent ); mSchema << data.schema; } else if ( !mInlineSimpleType ) { // Or wait until all data are available generateSchema ( data, nIndent ); mSchema << data.schema; } }
void *NclConnectorsParser::parseCausalConnector( DOMElement *parentElement, void *objGrandParent) { wclog << "parseCausalConnector" << endl; void *parentObject = NULL; DOMNodeList *elementNodeList; DOMElement *element; DOMNode *node; string elementTagName = ""; void *elementObject = NULL; //pre-compile attributes parentObject = createCausalConnector(parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); for (int i = 0; i < (int)elementNodeList->getLength(); i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE) { element = (DOMElement*)node; elementTagName = XMLString::transcode( element->getTagName()); wclog << ">>" << elementTagName.c_str() << ": "; wclog << XMLString::transcode(element->getAttribute(XMLString::transcode("id"))) << endl; if (XMLString::compareIString(elementTagName.c_str(), "simpleCondition") == 0) { elementObject = parseSimpleCondition( element, parentObject); if (elementObject != NULL) { addSimpleConditionToCausalConnector( parentObject, elementObject); } } else if (XMLString::compareIString( elementTagName.c_str(), "simpleAction") == 0) { elementObject = parseSimpleAction( element, parentObject); if (elementObject != NULL) { addSimpleActionToCausalConnector( parentObject, elementObject); } } else if (XMLString::compareIString( elementTagName.c_str(), "compoundAction") == 0) { elementObject = parseCompoundAction( element, parentObject); if (elementObject != NULL) { addCompoundActionToCausalConnector( parentObject, elementObject); } } else if (XMLString::compareIString( elementTagName.c_str(), "connectorParam") == 0) { elementObject = parseConnectorParam( element, parentObject); if (elementObject != NULL) { addConnectorParamToCausalConnector( parentObject, elementObject); } } else if (XMLString::compareIString( elementTagName.c_str(), "compoundCondition") == 0) { elementObject = parseCompoundCondition( element, parentObject); if (elementObject != NULL) { addCompoundConditionToCausalConnector( parentObject, elementObject); } } } } return parentObject; }
void GetConfig::readConfigFile(string& configFile) throw (std::runtime_error) { // Test to see if the file is ok. struct stat fileStatus; int iretStat = stat(configFile.c_str(), &fileStatus); if (iretStat == ENOENT) throw(std::runtime_error( "Path file_name does not exist, or path is an empty string.")); else if (iretStat == ENOTDIR) throw(std::runtime_error("A component of the path is not a directory.")); else if (iretStat == ELOOP) throw(std::runtime_error( "Too many symbolic links encountered while traversing the path.")); else if (iretStat == EACCES) throw(std::runtime_error("Permission denied.")); else if (iretStat == ENAMETOOLONG) throw(std::runtime_error("File can not be read\n")); // Configure DOM parser. m_ConfigFileParser->setValidationScheme(XercesDOMParser::Val_Never); m_ConfigFileParser->setDoNamespaces(false); m_ConfigFileParser->setDoSchema(false); m_ConfigFileParser->setLoadExternalDTD(false); try { m_ConfigFileParser->parse(configFile.c_str()); // no need to free this pointer - owned by the parent parser object DOMDocument* xmlDoc = m_ConfigFileParser->getDocument(); // Get the top-level element: NAme is "root". No attributes for "root" DOMElement* elementRoot = xmlDoc->getDocumentElement(); if (!elementRoot) throw(std::runtime_error("empty XML document")); // Parse XML file for tags of interest: "ApplicationSettings" // Look one level nested within "root". (child of root) DOMNodeList* children = elementRoot->getChildNodes(); const XMLSize_t nodeCount = children->getLength(); // For all nodes, children of "root" in the XML tree. for (XMLSize_t i = 0; i < nodeCount; ++i) { DOMNode* currentNode = children->item(i); if (currentNode->getNodeType() && // true is not NULL currentNode->getNodeType() == DOMNode::ELEMENT_NODE) // is element { DOMElement* currentElement = dynamic_cast<xercesc::DOMElement*>(currentNode); if (XMLString::equals(currentElement->getTagName(), TAG_Player)) { const XMLCh* xmlch_Score = currentElement->getAttribute( ATTR_Score); m_Score = XMLString::transcode(xmlch_Score); const XMLCh* xmlch_HighSpeed = currentElement->getAttribute( ATTR_HighSpeed); m_HighSpeed = XMLString::transcode(xmlch_HighSpeed); const XMLCh* xmlch_HighTraction = currentElement->getAttribute(ATTR_HighTraction); m_HighTraction = XMLString::transcode(xmlch_HighTraction); const XMLCh* xmlch_HighTrack = currentElement->getAttribute( ATTR_HighTrack); m_HighTrack = XMLString::transcode(xmlch_HighTrack); const XMLCh* xmlch_MediumTrack = currentElement->getAttribute(ATTR_MediumTrack); m_MediumTrack = XMLString::transcode(xmlch_MediumTrack); const XMLCh* xmlch_Invicible = currentElement->getAttribute( ATTR_Invincible); m_Invincible = XMLString::transcode(xmlch_Invicible); break; // Data found. No need to look at other elements in tree. } } } } catch (xercesc::XMLException& e) { char* message = xercesc::XMLString::transcode(e.getMessage()); ostringstream errBuf; errBuf << "Error parsing file: " << message << flush; XMLString::release(&message); } }
static OGRCompoundCurve *getPolyline(DOMElement *elem) { // elem -> POLYLINE OGRCompoundCurve *ogrCurve = new OGRCompoundCurve(); OGRLineString *ls = new OGRLineString(); DOMElement *lineElem = (DOMElement *)elem->getFirstChild(); while (lineElem != NULL) { char* pszTagName = XMLString::transcode(lineElem->getTagName()); if (cmpStr(ILI2_COORD, pszTagName) == 0) { OGRPoint* poPoint = getPoint(lineElem); ls->addPoint(poPoint); delete poPoint; } else if (cmpStr(ILI2_ARC, pszTagName) == 0) { //Finish line and start arc if (ls->getNumPoints() > 1) { ogrCurve->addCurveDirectly(ls); ls = new OGRLineString(); } else { ls->empty(); } OGRCircularString *arc = new OGRCircularString(); // end point OGRPoint *ptEnd = new OGRPoint(); // point on the arc OGRPoint *ptOnArc = new OGRPoint(); // radius // double radius = 0; DOMElement *arcElem = (DOMElement *)lineElem->getFirstChild(); while (arcElem != NULL) { char* pszTagName2 = XMLString::transcode(arcElem->getTagName()); char* pszObjValue = getObjValue(arcElem); if (cmpStr("C1", pszTagName2) == 0) ptEnd->setX(CPLAtof(pszObjValue)); else if (cmpStr("C2", pszTagName2) == 0) ptEnd->setY(CPLAtof(pszObjValue)); else if (cmpStr("C3", pszTagName2) == 0) ptEnd->setZ(CPLAtof(pszObjValue)); else if (cmpStr("A1", pszTagName2) == 0) ptOnArc->setX(CPLAtof(pszObjValue)); else if (cmpStr("A2", pszTagName2) == 0) ptOnArc->setY(CPLAtof(pszObjValue)); else if (cmpStr("A3", pszTagName2) == 0) ptOnArc->setZ(CPLAtof(pszObjValue)); else if (cmpStr("R", pszTagName2) == 0) { // radius = CPLAtof(pszObjValue); } CPLFree(pszObjValue); XMLString::release(&pszTagName2); arcElem = (DOMElement *)arcElem->getNextSibling(); } OGRPoint *ptStart = getPoint((DOMElement *)lineElem->getPreviousSibling()); // COORD or ARC arc->addPoint(ptStart); arc->addPoint(ptOnArc); arc->addPoint(ptEnd); ogrCurve->addCurveDirectly(arc); delete ptStart; delete ptEnd; delete ptOnArc; } /* else { // TODO: StructureValue in Polyline not yet supported } */ XMLString::release(&pszTagName); lineElem = (DOMElement *)lineElem->getNextSibling(); } if (ls->getNumPoints() > 1) { ogrCurve->addCurveDirectly(ls); } else { delete ls; } return ogrCurve; }