QDomElement::setNodeValue not working!!

I am using QT 4.7
I have been having problems setting the value of a QDOMElement instance. The following is my code:

int main (int argc, char * argv[])
	QApplication app(argc,argv);
	QDomDocument d("bookml");
	QDomElement root = d.createElement("rootelement");
	QDomElement e = d.createElement("BookList");
	QDomElement e0 = d.createElement("BookName");
	e0.setNodeValue("The Da Vinci Code");
	QDomElement e1 = d.createElement("BookPrice");
	QFile mFile("test.xml");
	if ( !mFile.open(QIODevice::WriteOnly ) )
		std::cout << "Failed creating file" << std::endl;
		return -1;
	QTextStream s(&mFile);
	s << d.toString();
	return app.exec();

Open in new window

And as output in Internet Explorer I get:
<!DOCTYPE bookml (View Source for full doctype...)> 
- <rootelement>
- <BookList>
  <BookName /> 
  <BookPrice /> 

Open in new window

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.
Who is Participating?
irfan_omairConnect With a Mentor Commented:
void QDomElement::setAttribute ( const QString & name, const QString & value )

This should sove your problem.

setAttribute ("BookName" "The Vince code");

Let me know if this does not work
arjoshi77Author Commented:

what you said worked. But I am interested in knowing how to create child nodes with values as I have outlined in the code above.

Thanking you in advance for your time,
evilrixSenior Software Engineer (Avast)Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.