void MaiaObject::parseResponse(QString response, QNetworkReply* reply) { QDomDocument doc; QVariant arg; QString errorMsg; int errorLine; int errorColumn; if(!doc.setContent(response, &errorMsg, &errorLine, &errorColumn)) { emit fault(-32700, QString("parse error: response not well formed at line %1: %2").arg(errorLine).arg(errorMsg), reply); delete this; return; } if(doc.documentElement().firstChild().toElement().tagName().toLower() == "params") { QDomNode paramNode = doc.documentElement().firstChild().firstChild(); if(!paramNode.isNull()) { arg = fromXml( paramNode.firstChild().toElement() ); } emit aresponse(arg, reply); } else if(doc.documentElement().firstChild().toElement().tagName().toLower() == "fault") { const QVariant errorVariant = fromXml(doc.documentElement().firstChild().firstChild().toElement()); emit fault(errorVariant.toMap() [ "faultCode" ].toInt(), errorVariant.toMap() [ "faultString" ].toString(), reply); } else { emit fault(-32600, tr("parse error: invalid xml-rpc. not conforming to spec."), reply); } delete this; return; }
void MaiaObject::parseResponse(QString response) { QDomDocument doc; QVariant arg; if(!doc.setContent(response)) { emit fault(-32700, tr("parse error: response not well formed.")); delete this; return; } if(doc.documentElement().firstChild().toElement().tagName().toLower() == "params") { QDomNode paramNode = doc.documentElement().firstChild().firstChild(); if(!paramNode.isNull()) { arg = fromXml( paramNode.firstChild().toElement() ); } emit aresponse(arg); } else if(doc.documentElement().firstChild().toElement().tagName().toLower() == "fault") { const QVariant errorVariant = fromXml(doc.documentElement().firstChild().firstChild().toElement()); emit fault(errorVariant.toMap() [ "faultCode" ].toInt(), errorVariant.toMap() [ "faultString" ].toString()); } else { emit fault(-32600, tr("parse error: invalid xml-rpc. not conforming to spec.")); } delete this; return; }
QVariant MaiaObject::fromXml(const QDomElement &elem) { if(elem.tagName().toLower() != "value") { return QVariant(); } // If no type is indicated, the type is string. if(!elem.firstChild().isElement()) { return QVariant(elem.text()); } const QDomElement typeElement = elem.firstChild().toElement(); const QString typeName = typeElement.tagName().toLower(); if(typeName == "string") return QVariant(typeElement.text()); else if(typeName == "i4" || typeName == "int") return QVariant(typeElement.text().toInt()); else if(typeName == "double") return QVariant(typeElement.text().toDouble()); else if (typeName == "boolean") { if(typeElement.text().toLower() == "true" || typeElement.text() == "1") return QVariant(true); else return QVariant(false); } else if(typeName == "base64") return QVariant(QByteArray::fromBase64( typeElement.text().toLatin1())); else if(typeName == "datetime" || typeName == "datetime.iso8601") return QVariant(QDateTime::fromString(typeElement.text(), "yyyyMMddThh:mm:ss")); else if(typeName == "nil") // Non-standard extension: http://ontosys.com/xml-rpc/extensions.php return QVariant(); else if ( typeName == "array" ) { QList<QVariant> values; QDomNode valueNode = typeElement.firstChild().firstChild(); while(!valueNode.isNull()) { values << fromXml(valueNode.toElement()); valueNode = valueNode.nextSibling(); } return QVariant(values); } else if ( typeName == "struct" ) { QMap<QString, QVariant> map; QDomNode memberNode = typeElement.firstChild(); while(!memberNode.isNull()) { const QString key = memberNode.toElement().elementsByTagName("name").item(0).toElement().text(); const QVariant data = fromXml(memberNode.toElement().elementsByTagName("value").item(0).toElement()); map[key] = data; memberNode = memberNode.nextSibling(); } return QVariant(map); } else { qDebug() << "Cannot demarshal unknown type " << typeElement.tagName().toLower(); } return QVariant(); }
bool CComponentLibrary::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { CXmlElement childElement; CXmlElement::CChildIterator it(xmlElement); // XML populate all component libraries while (it.next(childElement)) { // Filter component library/type set elements if (childElement.getType() == "ComponentLibrary" || childElement.getType() == "ComponentTypeSet") { if (!fromXml(childElement, serializingContext)) { return false; } } else { // Regular child creation and populating CElement *pChild = createChild(childElement, serializingContext); if (!pChild || !pChild->fromXml(childElement, serializingContext)) { return false; } } } return true; }
void WsAccount::answerReceived(const std::string & answer, int requestId) { RecursiveMutex::ScopedLock lock(_mutex); if (!answer.empty()) { bool fromServer = false; bool isValid = false; IMAccountList imAccountList; fromXml( imAccountList, answer ); switch( _queryResult.getEnumMethod() ) { case QueryResult::EnumMethod_SaveUserNetwork: handleSet( imAccountList ); break; case QueryResult::EnumMethod_GetUserNetwork: handleGet( imAccountList ); break; case QueryResult::EnumMethod_RemoveUserNetwork: handleRemove(); break; default: LOG_WARN( "Unexpected method" ); assert(false); } } }
// ============================================================================ StatusCode Gaudi::Utils::Histos::fromXml ( AIDA::IProfile2D& result , const std::string& input ) { TProfile2D* root = Gaudi::Utils::Aida2ROOT::aida2root ( &result ) ; if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN // return fromXml ( *root , input ) ; // RETURN }
bool ViElement::loadFromFile(QString fileName) { QFile file(fileName); if(!file.open(QIODevice::ReadOnly)) { return false; } fromXml(file.readAll()); file.close(); return true; }
Race::Race(const QDomDocument& doc) throw(XmlParseException) : UnitList(), WargearList(), RuleSet(), m_name(), m_id() { m_game = NULL; QDomElement root = doc.documentElement(); if(root.isNull() || root.nodeName() != "race") throw XmlParseException("missing root race node"); fromXml(root); }
ValueTree ValueTree::fromXml (const XmlElement& xml) { ValueTree v (xml.getTagName()); const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator.. for (int i = 0; i < numAtts; ++i) v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0); forEachXmlChildElement (xml, e) { v.addChild (fromXml (*e), -1, 0); }
// ============================================================================ StatusCode Gaudi::Utils::Histos::fromXml ( TProfile2D*& result , const std::string& input ) { if ( 0 != result ) { return fromXml ( *result , input ) ; } // _Xml<TProfile2D> _xml ; std::auto_ptr<TProfile2D> histo = _xml ( input ) ; if ( 0 == histo.get() ) { return StatusCode::FAILURE ; } // RETURN // result = histo.release() ; // ASSIGN // return StatusCode::SUCCESS ; }
TaskList Task::readTasksElement( const QDomElement& element, int databaseSchemaVersion ) { if ( element.tagName() == taskListTagName() ) { TaskList tasks; for ( QDomElement child = element.firstChildElement(); !child.isNull(); child = child.nextSiblingElement( tagName() ) ) { if ( child.tagName() != tagName() ) { throw XmlSerializationException( QObject::tr( "Task::readTasksElement: parent-child mismatch" ) ); } Task task = fromXml( child, databaseSchemaVersion ); tasks << task; } return tasks; } else { throw XmlSerializationException( QObject::tr( "Task::readTasksElement: judging by the tag name, this is not a tasks element" ) ); } }
QList<ModelDescriptor *> ModelDescriptor::fromXml(QDomDocument modelDescriptorDocument, QObject *parent) { Q_UNUSED(parent) QDomElement rootElement = modelDescriptorDocument.firstChildElement("ModelDescriptors"); if(rootElement.isNull()) { throw tr("Document did not contain 'ModelDescriptors' element as its root"); } QList<ModelDescriptor *> modelDescriptors; QDomElement modelDescriptorElement = rootElement.firstChildElement("ModelDescriptor"); while(!modelDescriptorElement.isNull()) { modelDescriptors.append(fromXml(modelDescriptorElement)); modelDescriptorElement = modelDescriptorElement.nextSiblingElement(modelDescriptorElement.tagName()); } return modelDescriptors; }
QList<ModelDescriptor *> ModelDescriptor::fromXml(const QString &filePath, QObject *parent) { QDomDocument document = QDomDocument("ModelDescriptors"); QFile file(filePath); if (!file.open(QIODevice::ReadOnly)) { throw tr("Could not open model description file: %1").arg(filePath); } if (!document.setContent(&file)) { file.close(); throw tr("Could not use model description file after opening --possibly invalid text"); } file.close(); return fromXml(document, parent); }
Creature * Creature::fromXml(const std::string& xml, bool* ok) { QDomDocument doc; QString * error_msg = new QString(); int* error_line = new int(); int* error_col = new int(); *ok = doc.setContent(QString(xml.c_str()), error_msg, error_line, error_col); if (!*ok) { BDEBUG("Error: " + error_msg->toStdString() + " at [" + TO_STRING(*error_line) + " , " + TO_STRING(*error_col) + "]"); } delete error_msg; delete error_line; delete error_col; if (!*ok) { return NULL; } QDomElement root = doc.firstChild().toElement(); return fromXml(root, ok); }
Document* Document::fromFile(QString filename) { QFile f(filename); if(!f.open(QIODevice::ReadOnly)) return 0; QDomDocument doc; if(!doc.setContent(&f)) { f.close(); return 0; } Document *d = fromXml(doc.documentElement()); if(d) { d->fileName = filename; int ind = std::max(filename.lastIndexOf("/"), filename.lastIndexOf("\\")); d->_name = filename.mid(ind+1); return d; } else return 0; }
GeoLocation::GeoLocation(const QDomElement& el) { floor_ = -100; fromXml(el); }
StatusPreset::StatusPreset(const QDomElement& el) : name_(""), message_(""), status_(XMPP::Status::Away) { fromXml(el); }
PubSubSubscription::PubSubSubscription(const QDomElement& e) { fromXml(e); }
PrivacyList::PrivacyList(const QDomElement& e) { fromXml(e); }
GeoLocation::GeoLocation(const QDomElement& el) { fromXml(el); }
PlayerDetails::PlayerDetails(XML& xml){ fromXml(xml); }
SellerManager::SellerManager() { m_fileName = "Sellers.xml"; fromXml(); }
PrivacyListItem::PrivacyListItem(const QDomElement& e) { fromXml(e); }
JobEventList JobEventList::fromXml(const QString &xml) { QList<qint64> empty; return fromXml(xml, "", empty); }
URLBookmark::URLBookmark(const QDomElement& el) { fromXml(el); }
Mood::Mood(const QDomElement& e) { fromXml(e); }
PhysicalLocation::PhysicalLocation(const QDomElement& el) { fromXml(el); }
Recipe::Recipe(QDomElement element, QObject *parent) : QObject(parent) { fromXml(element); }
RecipeIngredient::RecipeIngredient(QDomElement element, QObject *parent) : QObject(parent) { fromXml(element); }