hello:
I have been having problems setting the value of a QDOMElement instance. The following is my code:
int main (int argc, char * argv[])
{
d.appendChild(root);
root.appendChild(e);
e.appendChild(e0);
e0.setNodeValue("The Da Vinci Code");
e1.setNodeValue("45.50");
e.appendChild(e1);
{
std::cout << "Failed creating file" << std::endl;
return -1;
}
s << d.toString();
mFile.close();
return app.exec();
}
int main (int argc, char * argv[])
{
QApplication app(argc,argv);
QDomDocument d("bookml");
QDomElement root = d.createElement("rootelement");
d.appendChild(root);
QDomElement e = d.createElement("BookList");
root.appendChild(e);
QDomElement e0 = d.createElement("BookName");
e.appendChild(e0);
e0.setNodeValue("The Da Vinci Code");
QDomElement e1 = d.createElement("BookPrice");
e1.setNodeValue("45.50");
e.appendChild(e1);
QFile mFile("test.xml");
if ( !mFile.open(QIODevice::WriteOnly ) )
{
std::cout << "Failed creating file" << std::endl;
return -1;
}
QTextStream s(&mFile);
s << d.toString();
mFile.close();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
And as output in Internet Explorer I get:
<!DOCTYPE bookml (View Source for full doctype...)>
- <rootelement>
- <BookList>
<BookName />
<BookPrice />
</BookList>
</rootelement>
<!DOCTYPE bookml (View Source for full doctype...)>
- <rootelement>
- <BookList>
<BookName />
<BookPrice />
</BookList>
</rootelement>
To copy to clipboard, switch view to plain text mode
One can notice that the tags are formed but the values of the BookName and BookPrice which I am supplying using the setNodeValue method are not being seen here.
Any help would be appreciated.
Bookmarks