qtxml

QDomDocument fails to set content of an HTML document with <!doctype> tag

北城余情 提交于 2020-01-12 19:37:32
问题 When I use QDomDocument with HTML content, it fails to set content if there is a <!doctype html> at the beginning of the document. But actually why?! for example consider the following snippet of code: QDomDocument doc; QString content = "<!doctype html><html><body><a href='bar'>foo</a></body></html>"; qDebug() << doc.setContent(content,false,0,0); QDomElement docElem = doc.documentElement(); QDomNode a = docElem.firstChild(); qDebug() << doc.childNodes().size() << docElem.childNodes().size()

Writing XML Nodes in QtXML (QDomElement)

人走茶凉 提交于 2020-01-05 07:50:37
问题 I would like to write Nodes like <name>Peter</name> (with start and end tag) into a QDomDocument. When I create QDomElements and append them as child to a parent element: QDomElement node = doc.createElement("node"); parent.appendChild(node); They are added as <node/> to the parent element. The parent automatically gets a start and end tag so the file would look like this: <parent> <node/> </parent> But how do I add a value to my node so that it looks like I want it (with value between start

How to convert QString to QDomElement?

99封情书 提交于 2019-12-12 01:57:00
问题 I've QDomElement object converted to QString via element.text() method and stored in mysql database in text format. I've a problem while extracting it from database, because having extracted from database it has a format of QString, so I need to convert it again to QDomElement in order to further implement smth with that object. How can I do this? 回答1: You can parse the string into a QDomDocument and then extract the whole tree: QString input("<xml></xml>"); QDomDocument xmlDoc; xmlDoc

Incorrect order of attributes in Qt XML

僤鯓⒐⒋嵵緔 提交于 2019-12-01 19:35:09
I have the following code: element.clear(); element.setTagName("accountpoint"); element.setAttribute("code", QString(ID_CONST)+serial); element.setAttribute("name", QString()); element.setAttribute("serial", serial); QFile file(filename); file.open(QIODevice::ReadWrite); QTextStream stream(&file); doc.save(stream, 4); I thought I will get an XML like: <accountpoint code="4871583314750580" name="" serial="14750580"> But I have: <accountpoint serial="14750580" code="4871583314750580" name=""> Why? P.S. Yes, of course, in XML document it does not matter, but I want to get the right order of

Incorrect order of attributes in Qt XML

允我心安 提交于 2019-12-01 18:07:22
问题 I have the following code: element.clear(); element.setTagName("accountpoint"); element.setAttribute("code", QString(ID_CONST)+serial); element.setAttribute("name", QString()); element.setAttribute("serial", serial); QFile file(filename); file.open(QIODevice::ReadWrite); QTextStream stream(&file); doc.save(stream, 4); I thought I will get an XML like: <accountpoint code="4871583314750580" name="" serial="14750580"> But I have: <accountpoint serial="14750580" code="4871583314750580" name="">

QEventLoop: Cannot be used without QApplication

我与影子孤独终老i 提交于 2019-12-01 04:56:48
问题 I'm trying to validate an xml file against a specific schema. So I'm loading the schema into the QXmlSchema object. But I get some strange errors. My code looks like: int main() { QUrl url("http://www.schema-example.org/myschema.xsd"); QXmlSchema schema; if (schema.load(url) == true) qDebug() << "schema is valid"; else qDebug() << "schema is invalid"; return 1; } When I try to run the above piece of code, Qt errors out saying: QEventLoop: Cannot be used without QApplication QDBusConnection:

Edit Value of a QDomElement?

不羁岁月 提交于 2019-11-28 09:12:58
I need to edit the text of a QDomElement - Eg I have an XML file with its content as - <root> <firstchild>Edit text here</firstchild> </root> How do I edit the text of the child element <firstchild> ? I don't see any functions in the QDomElement of QDomDocument classes descriptions provided in Qt 4.7 Edit1 - I am adding more details. I need to read, modify and save an xml file. To format of the file is as below - <root> <firstchild>Edit text here</firstchild> </root> The value of element needs to be edited.I code to read the xml file is - QFile xmlFile(".\\iWantToEdit.xml"); xmlFile.open

Edit Value of a QDomElement?

折月煮酒 提交于 2019-11-27 02:43:12
问题 I need to edit the text of a QDomElement - Eg I have an XML file with its content as - <root> <firstchild>Edit text here</firstchild> </root> How do I edit the text of the child element <firstchild> ? I don't see any functions in the QDomElement of QDomDocument classes descriptions provided in Qt 4.7 Edit1 - I am adding more details. I need to read, modify and save an xml file. To format of the file is as below - <root> <firstchild>Edit text here</firstchild> </root> The value of element