[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1051
  • Last Modified:

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.
0
arjoshi77
Asked:
arjoshi77
1 Solution
 
irfan_omairCommented:
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now