如何从包含多个XML节点的QString中创建QDomDocument?我知道一种方法是使用setContent方法,但这不是更好的方法,如果我需要从包含类似以下内容的字符串创建XML:
我需要传递像setContent字符串这样的内容。
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
我需要传递像setContent字符串这样的内容。
rhythmdb.setContent("<?xml version='1.0' encoding='UTF-8'?>"
" <breakfast_menu>"+res+"</breakfast_menu");
从setContent指定xml版本和编码不是一个好的方法。
我需要创建
QDomDocument rhythmdb;
为rhythmdb指定XML版本和编码
创建子元素,如
QDomElement childElement= rhythmdb.createElement("breakfast_menu");
附加
breakfast_menu
元素的XML内容,如childElement.setContent(res);
但是,QDomElement
对象没有setContent
方法。
我该如何编写程序呢?
谢谢。
QString
指定编码类型,最好指定正确的编码类型:UTF-16。 - MrEricSir