QDomElement::setNodeValue not working!!

hello:
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");
	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();
}

Open in new window


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

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.
arjoshi77Asked:
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
0
 
arjoshi77Author Commented:
irfan:

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,
0
 
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.
0
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.