QDomElement::setNodeValue not working!!

Posted on 2011-05-02
Last Modified: 2012-05-11
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 ( ! ) )
		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.
Question by:arjoshi77
    LVL 7

    Accepted Solution

    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

    Author Comment


    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,
    LVL 39

    Expert Comment

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    maze travler 6 38
    Building cUrl in Windows v7.43.0 4 22
    Embarcadero C++ Builder XE2 TDateTime 8 51
    How to split this in C++ 4 55
    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
    IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now