I am trying to read xml tags from a document using QtXQuery. Works out fine besides a '\n'-char that is attached to each query-result. Moreover using the last()-statement on a collection returns the expected number of items in the collection with a trailing repetition + '\n'. Why QXmlQuery seem to add a ` \n` to results? (and how to solve it?) suggest to use a QStringList and only take the first item into account, yet this does not seem to work with my setup as using a QStringList on query.evaluateTo(&qsl) fails to return any results. So: my question is if this is a bug in libqt5xmlPatterns5 or if my implementation is the reason for this behavior? Am I missing some details on how to use QtXmlQuery? So here is the piece of code:
get_tag_value:
static lib_int_err_t get_tag_value(QString *result, QUrl schema_file, QString xml_file_name, QString var_name, QString query_str) { lib_int_err_t ret_code = LIE_OK; QFile *xml_f= new QFile(xml_file_name); xml_f->open(QIODevice::ReadOnly); if(result!=nullptr){ result->clear(); QXmlSchema xmlschema; // QStringList *results = new QStringList(); xmlschema.load(schema_file); QXmlQuery query(QXmlQuery::XQuery10, xmlschema.namePool()); query.bindVariable(var_name, xml_f); query.setQuery(query_str); query.evaluateTo(result); // result->append(results->first()); ret_code = LIE_OK; } else{ ret_code = LIE_XML_MALFORMED; } xml_f->close(); return ret_code; }
The input query string:
'declare copy-namespaces no-preserve, inherit; declare variable $" + var_name + " external; doc($" + var_name + ")" + "//procLib/last()" '
The schema used for data description:
<xs:element name="toolConfig"> <xs:complexType> <xs:sequence> <xs:element name="processingLibsSettings"> <xs:complexType> <xs:sequence> <xs:element name="interfaceSchemaDef" type="xs:string" minOccurs="1" maxOccurs="1"/> <xs:element name="interfaceSchemaPath" type="xs:string" minOccurs="1" maxOccurs="1"/> <xs:element name="processingLibsInstances"> <xs:complexType> <xs:sequence maxOccurs="unbounded"> <xs:element name="procLib" minOccurs="0"> <xs:complexType> <xs:sequence> <xs:element name="procLibConfigName" type="xs:string"/> <xs:element name="procLibConfigPath" type="xs:string"/> <xs:element name="procLibName" type="xs:string"/> <xs:element name="procLibPath" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="installDir" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>