bool KoDocumentInfo::saveOasisAboutInfo(KoXmlWriter &xmlWriter) { saveParameters(); foreach(const QString & tag, m_aboutTags) { if (!aboutInfo(tag).isEmpty() || tag == "title") { if (tag == "keyword") { foreach(const QString & tmp, aboutInfo("keyword").split(';')) { xmlWriter.startElement("meta:keyword"); xmlWriter.addTextNode(tmp); xmlWriter.endElement(); } } else if (tag == "title" || tag == "description" || tag == "subject" || tag == "date") { QByteArray elementName(QString("dc:" + tag).toLatin1()); xmlWriter.startElement(elementName); xmlWriter.addTextNode(aboutInfo(tag)); xmlWriter.endElement(); } else { QByteArray elementName(QString("meta:" + tag).toLatin1()); xmlWriter.startElement(elementName); xmlWriter.addTextNode(aboutInfo(tag)); xmlWriter.endElement(); } }
/* * The Cl- species is special in the sense that its single ion * molality-based activity coefficient is used in the specification * of the pH scale for single ions. Therefore, we need to know * what species index Cl- is. If the species isn't in the species * list then this routine returns -1, and we can't use the NBS * pH scale. * * Right now we use a restrictive interpretation. The species * must be named "Cl-". It must consist of exactly one Cl and one E * atom. */ size_t MolalityVPSSTP::findCLMIndex() const { size_t indexCLM = npos; size_t eCl = npos; size_t eE = npos; size_t ne = nElements(); string sn; for (size_t e = 0; e < ne; e++) { sn = elementName(e); if (sn == "Cl" || sn == "CL") { eCl = e; break; } } // We have failed if we can't find the Cl element index if (eCl == npos) { return npos; } for (size_t e = 0; e < ne; e++) { sn = elementName(e); if (sn == "E" || sn == "e") { eE = e; break; } } // We have failed if we can't find the E element index if (eE == npos) { return npos; } for (size_t k = 1; k < m_kk; k++) { doublereal nCl = nAtoms(k, eCl); if (nCl != 1.0) { continue; } doublereal nE = nAtoms(k, eE); if (nE != 1.0) { continue; } for (size_t e = 0; e < ne; e++) { if (e != eE && e != eCl) { doublereal nA = nAtoms(k, e); if (nA != 0.0) { continue; } } } sn = speciesName(k); if (sn != "Cl-" && sn != "CL-") { continue; } indexCLM = k; break; } return indexCLM; }
void XMLFileElement::writeElement(QXmlStreamWriter* xml_writer){ if (hasSubElements()) xml_writer->writeStartElement(elementName()); else xml_writer->writeEmptyElement(elementName()); writeAttributes(xml_writer); writeSubElements(xml_writer); if (hasSubElements()) xml_writer->writeEndElement(); }
void Authors::readAuthor() { Author author; nextToken(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("id")) { author.id = readText(); } else if (elementNameEquals("name")) { author.name = readText(); } else if (elementNameEquals("address")) { author.address = readText(); } else if (elementNameEquals("email")) { author.email = readText(); } else { throw Exception(message("Unexpected element: '" + elementName() + "'")); } } if (author.id.label().isEmpty()) throw Exception(message("Missing author id")); if (author.name.isEmpty()) throw Exception(message("Missing author name")); if (author.address.isEmpty()) throw Exception(message("Missing author address")); if (theCollection.contains(author.id)) throw Exception(message("Author id occurs twice")); theCollection[author.id] = author; }
bool SimulationMaker::readOutputElement(QObject* parent) { Q_ASSERT(reader->isStartElement() && parent); QString objectName = attributeValue("name"); if (objectName.isEmpty()) objectName = "anonymous"; QString type = attributeValue("type").toLower(); Output *output; try { output = OutputMaker::create(type, objectName, parent); } catch (Exception &ex) { throw Exception(message(ex.message())); } nextElementDelim(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("parameter")) { readParameterElement(output); } else if (elementNameEquals("variable")) { readVariableElement(output); } else { throw Exception(message( "Unknown element in 'output' element: " + elementName())); } } Q_ASSERT(reader->isEndElement()); nextElementDelim(); return output; }
void MineralEQ3::convertDGFormation() { // Ok let's get the element compositions and conversion factors. doublereal totalSum = 0.0; for (size_t m = 0; m < nElements(); m++) { double na = nAtoms(0, m); if (na > 0.0) { totalSum += na * LookupGe(elementName(m)); } } // Ok, now do the calculation. Convert to joules kmol-1 doublereal dg = m_deltaG_formation_pr_tr * toSI("cal/gmol"); //! Store the result into an internal variable. m_Mu0_pr_tr = dg + totalSum; double Hcalc = m_Mu0_pr_tr + 298.15 * m_Entrop_pr_tr * toSI("cal/gmol"); double DHjmol = m_deltaH_formation_pr_tr * toSI("kal/gmol"); // If the discrepancy is greater than 100 cal gmol-1, print an error if (fabs(Hcalc -DHjmol) > 100 * toSI("cal/gmol")) { throw CanteraError("installMinEQ3asShomateThermoFromXML()", "DHjmol is not consistent with G and S: {} vs {}", Hcalc, DHjmol); } }
void MineralEQ3::convertDGFormation() { /* * Ok let's get the element compositions and conversion factors. */ int ne = nElements(); doublereal na; doublereal ge; string ename; doublereal totalSum = 0.0; for (int m = 0; m < ne; m++) { na = nAtoms(0, m); if (na > 0.0) { ename = elementName(m); ge = LookupGe(ename); totalSum += na * ge; } } // Add in the charge // if (m_charge_j != 0.0) { // ename = "H"; // ge = LookupGe(ename); // totalSum -= m_charge_j * ge; //} // Ok, now do the calculation. Convert to joules kmol-1 doublereal dg = m_deltaG_formation_pr_tr * 4.184 * 1.0E3; //! Store the result into an internal variable. m_Mu0_pr_tr = dg + totalSum; }
void Authors::initialize() { QFile file(":/authors.xml"); if (!file.open(QIODevice::ReadOnly)) throw Exception("Cannot fint embedded file 'authors.xml"); reader->setDevice(&file); nextToken(); if (!reader->isStartElement() && elementNameEquals("authors")) throw Exception(message("Expected <authors> element'")); nextToken(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("author")) { readAuthor(); } else { throw Exception(message("Unexpected element: '" + elementName() + "'")); } if(!reader->isEndElement()) throw Exception(message("Expected end element </author>")); nextToken(); } //nextToken(); if(!reader->isEndElement()) throw Exception(message("Expected end element </authors>")); }
void ScenarioLoiteringTrajectory::writeElement(QXmlStreamWriter* out) { out->writeStartElement(elementName()); //out->writeAttribute("Name", name()); writeContents(out); out->writeEndElement(); }
Simulation* SimulationMaker::parse(QString fileName_) { QString simName, simVersion; redirectedParameters.clear(); outputVariableParam.clear(); outputParameterParam.clear(); outputDataParam.clear(); emit beginExpansion(); fileName = compileToFile(fileName_); emit endExpansion(); QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) throw Exception(message("Cannot open file: '"+fileName+"' for reading.")); reader->setDevice(&file); if (!nextElementDelim()) throw Exception(message("File is not in valid XML format")); if (elementNameNotEquals("simulation")) throw Exception(message("Root element must be 'simulation'")); simName = attributeValue("name", "anonymous"); simVersion = attributeValue("version", "1.0"); Simulation *sim = new Simulation(simName, simVersion); UniSim::setSimulationObject(sim); nextElementDelim(); int iCon=0, iMod=0, iOut=0; while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("integrator") || elementNameEquals("controller")) { if (readIntegratorElement(sim)) ++iCon; } else if (elementNameEquals("model")) { if (readModelElement(sim)) ++iMod; } else if (elementNameEquals("output")) { if (readOutputElement(sim)) ++iOut; } else { throw Exception(message("Unexpected element: '" + elementName() + "'"), sim); } } Q_ASSERT(reader->isEndElement()); if (reader->hasError()) throw Exception(message("")); if (iCon==0) throw Exception(message("Missing 'integrator' element in 'simulation'")); else if (iCon>1) throw Exception(message("Only one 'integrator' element allowed in 'simulation'")); if (iMod==0) throw Exception(message("Missing 'model' element in 'simulation'")); if (iOut==0) throw Exception(message("Missing 'output' element in 'simulation'")); redirectParameters(); reader->clear(); emit beginInitialization(); sim->initialize(_sequence, this); emit endInitialization(); return sim; }
bool SimulationMaker::readModelElement(QObject* parent) { Q_ASSERT(reader->isStartElement()); QString modelType = attributeValue("type", "anonymous"); QString objectName = attributeValue("name", "anonymous"); QString hide = attributeValue("hide", ""); QString instancesStr = attributeValue("instances", ""); bool manyInstances = !instancesStr.isEmpty(); int instances = 1; if (manyInstances) { bool ok(true); instances = instancesStr.toInt(&ok); if (!ok || instances <= 0) throw Exception("instances must a number larger than zero"); } Model *model; try { for (int i = 0; i < instances; ++i) { QString objectInstanceName = objectName; if (manyInstances) objectInstanceName += "(" + QString::number(i+1) + ")"; model = ModelMaker::create(modelType, objectInstanceName, parent); if (!hide.isEmpty()) { bool isHidden = UniSim::stringToValue<bool>(hide); model->setHide(isHidden); } } } catch (Exception &ex) { throw Exception(message(ex.message()), parent); } nextElementDelim(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("model")) { readModelElement(model); } else if (elementNameEquals("dataset")){ readDatasetElement(model); } else if (elementNameEquals("parameter")){ readParameterElement(model); } else { throw Exception(message("Unexpected element: '" + elementName() + "'"), parent); } } Q_ASSERT(reader->isEndElement()); nextElementDelim(); return model; }
void gcatLibrary_XMLParser::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) { string element = elementName(localname); if(element=="libraries") { ++parsingLibraries; } else { // Ignore } }
bool SimulationMaker::nextElementDelim() { QString myTest = elementName(); QXmlStreamReader::TokenType myType; bool unusedElement; if (moreToRead()) { do { reader->readNext(); myTest = elementName(); myType = reader->tokenType(); bool commonElement = reader->isStartElement() && elementNameEquals("common"); unusedElement = commonElement || !(reader->isStartElement() || reader->isEndElement()); if (commonElement) ignoreElement(); } while (unusedElement && moreToRead()); } return reader->isStartElement() || reader->isEndElement(); }
void MaterialObject::Element::populateMaterialProperties(MaterialProperties& materialProperties) const { double quantity; if(debugInactivate() == false) { if(service() == false) { quantity = totalGrams(materialProperties); materialProperties.addLocalMass(elementName(), componentName(), quantity); } } }
void Phase::addSpecies(const std::string& name_, const doublereal* comp, doublereal charge_, doublereal size_) { compositionMap cmap; for (size_t i = 0; i < nElements(); i++) { if (comp[i]) { cmap[elementName(i)] = comp[i]; } } Phase::addSpecies(Species(name_, cmap, 0, charge_, size_)); }
MaterialObject::Element::Element(const Element& original, double multiplier) : Element(original.materialType_) { if(original.destination.state()) destination(original.destination()); if(original.componentName.state()) componentName(original.componentName()); elementName(original.elementName()); service(original.service()); quantity(original.quantity() * original.scalingMultiplier() * multiplier); //apply the scaling in the copied object scaleOnSensor(0); unit(original.unit()); debugInactivate(original.debugInactivate()); }
Simulation* SimulationMaker::parse(QString fileName_) { fileName = fileName_; QString simName, simVersion; XmlExpander expander(fileName, "_expanded"); emit beginExpansion(); expander.expand(); emit endExpansion(); fileName = expander.newFileName(); QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) throw Exception(message("Cannot open file: '"+fileName+"' for reading.")); reader->setDevice(&file); if (!nextElementDelim()) throw Exception(message("File is not in valid XML format")); if (elementNameNotEquals("simulation")) throw Exception(message("Root element must be 'simulation'")); simName = attributeValue("name"); if (simName.isEmpty()) simName = "anonymous"; simVersion = attributeValue("version"); if (simVersion.isEmpty()) simVersion = "1.0"; Simulation *sim = new Simulation(simName, simVersion); UniSim::setSimulationObject(sim); nextElementDelim(); int iCon=0, iMod=0, iOut=0; while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("integrator") || elementNameEquals("controller")) { if (readIntegratorElement(sim)) ++iCon; } else if (elementNameEquals("model")) { if (readModelElement(sim)) ++iMod; } else if (elementNameEquals("output")) { if (readOutputElement(sim)) ++iOut; } else { throw Exception(message("Unknown element in 'simulation' element: " + elementName())); } } Q_ASSERT(reader->isEndElement()); if (reader->hasError()) throw Exception(message("")); if (iCon==0) throw Exception(message("Missing 'integrator' element in 'simulation'")); else if (iCon>1) throw Exception(message("Only one 'integrator' element allowed in 'simulation'")); if (iMod==0) throw Exception(message("Missing 'model' element in 'simulation'")); if (iOut==0) throw Exception(message("Missing 'output' element in 'simulation'")); reader->clear(); emit beginInitialization(); sim->initialize(_sequence); emit endInitialization(); return sim; }
bool SimulationMaker::readOutputElement(QObject* parent) { Q_ASSERT(reader->isStartElement() && parent); QString objectName = attributeValue("name", "anonymous"); QString type = attributeValue("type", parent); QString summary = attributeValue("summary", ""); Output *output; try { output = OutputMaker::create(type, objectName, parent); if (!summary.isEmpty()) { bool isSummary = UniSim::stringToValue<bool>(summary); output->setIsSummary(isSummary); } } catch (Exception &ex) { throw Exception(message(ex.message())); } nextElementDelim(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("parameter")) { readParameterElement(output); } else if (elementNameEquals("read-parameter")) { readOutputParameterElement(output); } else if (elementNameEquals("variable")) { readOutputVariableElement(output); } else if (elementNameEquals("data")) { readOutputDataElement(output); } else { throw Exception(message("Unexpected element: '" + elementName() + "'"), parent); } } Q_ASSERT(reader->isEndElement()); nextElementDelim(); return output; }
// ----------------------------------------------------------------------------- // CUpnpArgumentListContentHandler::OnStartElementL // This method is a callback to indicate an element has been parsed. // ----------------------------------------------------------------------------- // void CUpnpArgumentListContentHandler::OnStartElementL( const RTagInfo& aElement, const RAttributeArray& /*aAttributes*/ ) { TPtrC8 elementName(aElement.LocalName().DesC() ); if ( elementName.Compare( KUpnpArgument ) == 0 ) { CUpnpArgument* argument = CUpnpArgument::NewL( iResultService ); CleanupStack::PushL( argument ); iResultAction.AddArgumentL( *argument ); CleanupStack::Pop( argument ); iController.SetCurrentContentHandlerL( CUpnpArgumentContentHandler::NewL( iController, *argument ) ); } else { iController.SetCurrentContentHandlerL( CUpnpIgnoreContentHandler::NewL( iController ) ); } }
void MaterialObject::Element::deployMaterialTo(MaterialObject& outputObject, const std::vector<std::string>& unitsToDeploy, bool onlyServices /*= false*/, double gramsMultiplier /*= 1.*/) const { const Element* elementToDeploy = this; bool valid = false; if ((! onlyServices) || (onlyServices && (service() == true))) { if((unit().compare("g") == 0) && (service() == true)) { logERROR(err_service1 + elementName() + err_service2); } else { valid = true; } // if (materialType_ == STATION) { // if(unit().compare("g") == 0) { // logERROR(err_service1 + elementName() + err_service2); // } else { // valid = true; // } // } else if (materialType_ == ROD) { // if((unit().compare("g") == 0) && (service() == true) { // logERROR(err_service1 + elementName() + err_service2); // } else { // valid = true; // } // } else if (materialType_ == MODULE) { // if (service() == true) { // valid = true; // } // } if(valid) { for(const std::string& unitToDeploy : unitsToDeploy) { if (unit().compare(unitToDeploy) == 0) { if (((materialType_ == ROD) || (materialType_ == MODULE)) && (service()==true) && (unit().compare("mm") == 0)) { logUniqueWARNING("Definition of services in \"mm\" is deprecated"); } if (unit().compare("g") == 0) { elementToDeploy = new Element(*this, gramsMultiplier); } outputObject.addElement(elementToDeploy); break; } } } } }
void DocumentConverter::endElement(const XMLCh* const name) { XMLChToVXIchar elementName(name); int elemType; if (!ConvertElement(elementName.c_str(), elemType)) { vxistring temp(L"unrecognized element - "); temp += elementName.c_str(); ParseException(temp.c_str()); } if (IsIgnorable(elemType)) return; try { doc->EndElement(); } catch (const VXMLDocumentModel::InternalError &) { ParseException(L"corrupted document tree; unable to complete element"); } }
void SimulationMaker::readDatasetElement(QObject* parent) { Q_ASSERT(reader->isStartElement()); QString objectName = attributeValue("name", parent); Dataset *dataset = new Dataset(objectName, parent); nextElementDelim(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("parameter")){ readParameterElement(dataset); } else { throw Exception(message("Unexpected element: '" + elementName() + "'"), parent); } } Q_ASSERT(reader->isEndElement()); nextElementDelim(); }
void gcatLibrary_XMLParser::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs) { string element = elementName(localname); // Recognised elements if(element=="libraries") { ++parsingLibraries; } else if(element=="library") { // Only process library elements if they occur within the first block of <libraries>...</libraries> if(parsingLibraries==1) { // Read in the file name const int nattr = 1; const char* attrNames[nattr] = {"file"}; vector<string> sattr = attributesToStrings(nattr,attrNames,attrs); // Load the library, and add to the list of chameleon schemas. NB:- library must ensure it is not loaded multiple times getDAG()->add_chameleon(load_library(sattr[0].c_str())); } } else { // Ignore } }
void SimulationMaker::readSequenceElement(QObject* parent) { Q_ASSERT(reader->isStartElement() && parent); nextElementDelim(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("model")) { QString model = attributeValue("name", parent); _sequence.append(model); } else { throw Exception(message( "Unknown child element of 'sequence' element: " + elementName()), parent); } nextElementDelim(); Q_ASSERT(reader->isEndElement()); nextElementDelim(); } Q_ASSERT(reader->isEndElement()); nextElementDelim(); }
bool SimulationMaker::readIntegratorElement(QObject* parent) { Q_ASSERT(reader->isStartElement() && parent); QString type = attributeValue("type"); if (type.isEmpty()) throw Exception(message("Missing 'type' attribute for 'integrator' element")); QString name = attributeValue("name"); if (name.isEmpty()) name = "anonymous"; Integrator *integrator; try { integrator = IntegratorMaker::create(type, name, parent); } catch (Exception &ex) { throw Exception(message(ex.message())); } _sequence.clear(); nextElementDelim(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("sequence")) { readSequenceElement(integrator); } else if (elementNameEquals("parameter")){ readParameterElement(dynamic_cast<Parameters*>(integrator)); } else { throw Exception(message( "Unknown element in 'model' element: " + elementName())); } } Q_ASSERT(reader->isEndElement()); nextElementDelim(); return integrator; }
bool SimulationMaker::readIntegratorElement(QObject* parent) { Q_ASSERT(reader->isStartElement() && parent); QString type = attributeValue("type", parent); QString name = attributeValue("name", "anonymous"); Integrator *integrator; try { integrator = IntegratorMaker::create(type, name, parent); } catch (Exception &ex) { throw Exception(message(ex.message())); } _sequence.clear(); nextElementDelim(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("sequence")) { readSequenceElement(integrator); } else if (elementNameEquals("parameter")){ readParameterElement(integrator); } else if (elementNameEquals("model")){ readModelElement(integrator); } else { throw Exception(message( "Unexpected element: '" + elementName() + "'"), parent); } } Q_ASSERT(reader->isEndElement()); nextElementDelim(); return integrator; }
bool SimulationMaker::readModelElement(QObject* parent) { Q_ASSERT(reader->isStartElement()); QString modelType = attributeValue("type"); if (modelType.isEmpty()) modelType = "anonymous"; QString objectName = attributeValue("name"); if (objectName.isEmpty()) objectName = "anonymous"; Model *model; try { model = ModelMaker::create(modelType, objectName, parent); } catch (Exception &ex) { throw Exception(message(ex.message())); } nextElementDelim(); while (!reader->hasError() && reader->isStartElement()) { if (elementNameEquals("model")) { readModelElement(model); } else if (elementNameEquals("parameter")){ readParameterElement(dynamic_cast<Parameters*>(model)); } else { throw Exception(message( "Unknown element in 'model' element: " + elementName())); } } Q_ASSERT(reader->isEndElement()); nextElementDelim(); return model; }
double MaterialObject::Element::quantityInUnit(const std::string desiredUnit, const double length, const double surface) const { double returnVal = 0; double density = materialTab_.density(elementName()); bool invert; Unit desiredUnitVal, elementUnitVal, tempUnit; //Conversion matrix: // g g/m mm // __________________________________________________ // g | 1 l/1000 rho*S | // g/m | 1000/l 1 (rho*S*1000)/l | // mm | 1/(rho*S) l/(rho*S*1000) 1 | // // rows: desired unit // columns: original unit // l: length // rho: density // S: surface /* std::map<std::pair<Unit, Unit>, double> conversionMatrix = { {{GRAMS, GRAMS}, 1}, {{GRAMS, GRAMS_METER}, length/1000}, {{GRAMS, MILLIMETERS}, density*surface}, {{GRAMS_METER, GRAMS}, 1000/length}, {{GRAMS_METER, GRAMS_METER}, 1}, {{GRAMS_METER, MILLIMETERS}, (density*surface*1000)/length}, {{MILLIMETERS, GRAMS}, 1/(density*surface)}, {{MILLIMETERS, GRAMS_METER}, length/(density*surface*1000)}, {{MILLIMETERS, MILLIMETERS}, 1} }; try { returnVal = quantity() * conversionMatrix.at({unitStringMap.at(desiredUnit), unitStringMap.at(unit())}); } catch (const std::out_of_range& ex) { logERROR(msg_no_valid_unit + unit() + ", " + desiredUnit + "."); } */ try { desiredUnitVal = unitStringMap.at(desiredUnit); elementUnitVal = unitStringMap.at(unit()); if (desiredUnitVal == elementUnitVal) { return quantity(); } else if (desiredUnitVal > elementUnitVal) { invert = true; tempUnit = desiredUnitVal; desiredUnitVal = elementUnitVal; elementUnitVal = tempUnit; } else { invert = false; } if ((desiredUnitVal == GRAMS) && (elementUnitVal == GRAMS_METER)) returnVal = quantity() * length / 1000.; else if ((desiredUnitVal == GRAMS) && (elementUnitVal == MILLIMETERS)) returnVal = quantity() * density * surface; else if ((desiredUnitVal == GRAMS_METER) && (elementUnitVal == MILLIMETERS)) returnVal = quantity() * (density * surface * 1000.) / length; if (invert) returnVal = 1 / returnVal; } catch (const std::out_of_range& ex) { logERROR(msg_no_valid_unit + unit() + ", " + desiredUnit + "."); } return returnVal; }
void DocumentConverter::startElement(const XMLCh* const name, AttributeList & attrs) { XMLChToVXIchar elementName(name); // (1) Convert name string to enum. int elemType; if (!ConvertElement(elementName.c_str(), elemType)) { vxistring temp(L"unrecognized element - "); temp += elementName.c_str(); ParseException(temp.c_str()); } // (2) Check for ignored nodes and do version number processing. // (2.1) Catch illegal nodes and do version number processing. switch (elemType) { case DEFAULTS_ROOT: version = 2.0f; break; case NODE_VXML: { for (unsigned int index = 0; index < attrs.getLength(); ++index) { if (!Compare(attrs.getName(index), L"version")) continue; const XMLCh * attributeValue = attrs.getValue(index); if (Compare(attributeValue, L"1.0")) version = 1.0f; else if (Compare(attributeValue, L"2.0")) version = 2.0f; else ParseException(L"illegal version"); break; } break; } case PRIV_ELEM_DIV: case PRIV_ELEM_EMP: case PRIV_ELEM_PROS: case PRIV_ELEM_SAYAS: if (version != 1.0f) { vxistring temp(L"support for element '"); temp += elementName.c_str(); temp += L"' was dropped after VXML 1.0"; ParseException(temp.c_str()); } break; default: break; } // (2.2) Should we just ignore this node? if (IsIgnorable(elemType)) return; // (2.3) Convert nodes as necessary. switch (elemType) { case PRIV_ELEM_DIV: // Convert <div> into either <p> or <s>. if (attrs.getLength() == 1 && Compare(attrs.getName(0), L"paragraph")) elemType = NODE_PARAGRAPH; else elemType = NODE_SENTENCE; break; case PRIV_ELEM_EMP: elemType = NODE_EMPHASIS; break; case PRIV_ELEM_SAYAS: { elemType = NODE_SAYAS; for (unsigned int index = 0; index < attrs.getLength(); ++index) if (Compare(attrs.getName(index), L"phon")) { elemType = NODE_PHONEME; break; } break; } default: break; } // (3) Create new element. if (elemType > PRIV_ELEM_RangeStart) { vxistring temp(L"internal error for element - "); temp += elementName.c_str(); ParseException(temp.c_str()); } try { doc->StartElement(VXMLElementType(elemType)); } catch (const VXMLDocumentModel::OutOfMemory &) { ParseException(L"unable to allocate memory for element"); } catch (const VXMLDocumentModel::InternalError &) { ParseException(L"corrupted document tree; unable to add element"); } // (4) Add attributes to element. for (unsigned int index = 0; index < attrs.getLength(); ++index) { int attrType; // (4.1) Convert string to integer. XMLChToVXIchar attributeName(attrs.getName(index)); if (!ConvertAttribute(attributeName.c_str(), attrType)) { vxistring temp(L"unrecognized attribute - "); temp += attributeName.c_str(); ParseException(temp.c_str()); } // (4.2) Handle a few global settings. switch (attrType) { case PRIV_ATTRIB_CACHING: if (version != 1.0f) ParseException(L"the caching attribute was replaced by maxage and " L"maxstale after VXML 1.0"); if (Compare(attrs.getValue(index), L"safe")) { vxistring attr; if (!doc->GetAttribute(ATTRIBUTE_MAXAGE, attr)) doc->AddAttribute(ATTRIBUTE_MAXAGE, L"0"); } continue; default: break; } // (4.3) Handle internal values. XMLChToVXIchar attributeValue(attrs.getValue(index)); ProcessNodeAttribute(VXMLElementType(elemType), attrType, attributeValue.c_str()); } // (5) Verify the node. ProcessNodeFinal(VXMLElementType(elemType)); }
void QgsWFSData::endElement( const XML_Char* el ) { QString elementName( el ); QString localName = elementName.section( NS_SEPARATOR, 1, 1 ); if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "coordinates" ) { if ( !mParseModeStack.empty() ) { mParseModeStack.pop(); } } else if ( localName == mAttributeName ) //add a thematic attribute to the feature { if ( !mParseModeStack.empty() ) { mParseModeStack.pop(); } //find index with attribute name QMap<QString, QPair<int, QgsField> >::const_iterator att_it = mThematicAttributes.find( mAttributeName ); if ( att_it != mThematicAttributes.constEnd() ) { QVariant var; switch ( att_it.value().second.type() ) { case QVariant::Double: var = QVariant( mStringCash.toDouble() ); break; case QVariant::Int: var = QVariant( mStringCash.toInt() ); break; case QVariant::LongLong: var = QVariant( mStringCash.toLongLong() ); break; default: //string type is default var = QVariant( mStringCash ); break; } mCurrentFeature->addAttribute( att_it.value().first, QVariant( mStringCash ) ); } } else if ( localName == mGeometryAttribute ) { if ( !mParseModeStack.empty() ) { mParseModeStack.pop(); } } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "boundedBy" && mParseModeStack.top() == QgsWFSData::boundingBox ) { //create bounding box from mStringCash if ( createBBoxFromCoordinateString( mExtent, mStringCash ) != 0 ) { QgsDebugMsg( "creation of bounding box failed" ); } if ( !mParseModeStack.empty() ) { mParseModeStack.pop(); } } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "featureMember" ) { //MH090531: Check if all feature attributes are initialised, sometimes attribute values are missing. //We fill the not initialized ones with empty strings, otherwise the feature cannot be exported to shp later QgsAttributeMap currentFeatureAttributes = mCurrentFeature->attributeMap(); QMap<QString, QPair<int, QgsField> >::const_iterator att_it = mThematicAttributes.constBegin(); for ( ; att_it != mThematicAttributes.constEnd(); ++att_it ) { int attIndex = att_it.value().first; QgsAttributeMap::const_iterator findIt = currentFeatureAttributes.find( attIndex ); if ( findIt == currentFeatureAttributes.constEnd() ) { mCurrentFeature->addAttribute( attIndex, QVariant( "" ) ); } } mCurrentFeature->setGeometryAndOwnership( mCurrentWKB, mCurrentWKBSize ); mFeatures.insert( mCurrentFeature->id(), mCurrentFeature ); if ( !mCurrentFeatureId.isEmpty() ) { mIdMap.insert( mCurrentFeature->id(), mCurrentFeatureId ); } ++mFeatureCount; mParseModeStack.pop(); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "Point" ) { std::list<QgsPoint> pointList; if ( pointsFromCoordinateString( pointList, mStringCash ) != 0 ) { //error } if ( mParseModeStack.top() != QgsWFSData::multiPoint ) { //directly add WKB point to the feature if ( getPointWKB( &mCurrentWKB, &mCurrentWKBSize, *( pointList.begin() ) ) != 0 ) { //error } if ( *mWkbType != QGis::WKBMultiPoint ) //keep multitype in case of geometry type mix { *mWkbType = QGis::WKBPoint; } } else //multipoint, add WKB as fragment { unsigned char* wkb = 0; int wkbSize = 0; std::list<unsigned char*> wkbList; std::list<int> wkbSizeList; if ( getPointWKB( &wkb, &wkbSize, *( pointList.begin() ) ) != 0 ) { //error } mCurrentWKBFragments.rbegin()->push_back( wkb ); mCurrentWKBFragmentSizes.rbegin()->push_back( wkbSize ); //wkbList.push_back(wkb); //wkbSizeList.push_back(wkbSize); //mCurrentWKBFragments.push_back(wkbList); //mCurrentWKBFragmentSizes.push_back(wkbSizeList); } } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "LineString" ) { //add WKB point to the feature std::list<QgsPoint> pointList; if ( pointsFromCoordinateString( pointList, mStringCash ) != 0 ) { //error } if ( mParseModeStack.top() != QgsWFSData::multiLine ) { if ( getLineWKB( &mCurrentWKB, &mCurrentWKBSize, pointList ) != 0 ) { //error } if ( *mWkbType != QGis::WKBMultiLineString )//keep multitype in case of geometry type mix { *mWkbType = QGis::WKBLineString; } } else //multiline, add WKB as fragment { unsigned char* wkb = 0; int wkbSize = 0; std::list<unsigned char*> wkbList; std::list<int> wkbSizeList; if ( getLineWKB( &wkb, &wkbSize, pointList ) != 0 ) { //error } mCurrentWKBFragments.rbegin()->push_back( wkb ); mCurrentWKBFragmentSizes.rbegin()->push_back( wkbSize ); //wkbList.push_back(wkb); //wkbSizeList.push_back(wkbSize); //mCurrentWKBFragments.push_back(wkbList); //mCurrentWKBFragmentSizes.push_back(wkbSizeList); } } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "LinearRing" ) { std::list<QgsPoint> pointList; if ( pointsFromCoordinateString( pointList, mStringCash ) != 0 ) { //error } unsigned char* wkb; int wkbSize; if ( getRingWKB( &wkb, &wkbSize, pointList ) != 0 ) { //error } mCurrentWKBFragments.rbegin()->push_back( wkb ); mCurrentWKBFragmentSizes.rbegin()->push_back( wkbSize ); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "Polygon" ) { if ( *mWkbType != QGis::WKBMultiPolygon )//keep multitype in case of geometry type mix { *mWkbType = QGis::WKBPolygon; } if ( mParseModeStack.top() != QgsWFSData::multiPolygon ) { createPolygonFromFragments(); } } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiPoint" ) { *mWkbType = QGis::WKBMultiPoint; if ( !mParseModeStack.empty() ) { mParseModeStack.pop(); } createMultiPointFromFragments(); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiLineString" ) { *mWkbType = QGis::WKBMultiLineString; if ( !mParseModeStack.empty() ) { mParseModeStack.pop(); } createMultiLineFromFragments(); } else if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "MultiPolygon" ) { *mWkbType = QGis::WKBMultiPolygon; if ( !mParseModeStack.empty() ) { mParseModeStack.pop(); } createMultiPolygonFromFragments(); } }