简体   繁体   English

doc.documentElement()不返回根元素?

[英]doc.documentElement() does not return root element?

I am currently working on a XML parser and I am using Qt to make it. 我目前正在研究XML解析器,并且正在使用Qt进行解析。 Actually I have coded lots of things and functions but now I got a weird problem. 实际上,我已经编写了很多东西和函数,但是现在遇到了一个奇怪的问题。 When I make; 当我做

QDomElement root = doc.documentElement();

It never return root element. 它从不返回根元素。 I debugged it and I can see doc has a value but never returns root element. 我调试了它,可以看到doc具有一个值,但是从不返回根元素。 What can be the problem ? 可能是什么问题?

Thank you all 谢谢你们

If you have created an empty QDomDocument it has no root element. 如果创建了空的QDomDocument,则它没有根元素。 You need to create one: 您需要创建一个:

QDomElement root = doc.createElement("myroot");
doc.appendChild(root);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM