用过几次XML,每次用完就忘了,这次记录一下。
首先了解XML格式里面的元素,随便找个例子
<bookstore> <book category="CHILDREN"> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title>Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
<bookstore> 标签tag,QT中使用createElement生成标签,也可以使用setTagName
<book category="CHILDREN"> category是属性attribute,"CHILDREN"是属性值value 可以使用setAttribute实现设置。
<title>Harry Potter</title> <title>标签tag Harry Potter 内容content 或value。内容可以用 QDomText定义,然后使用QDomElement的appendChild 添加到标签中间。