[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Writing xml with mfc app

Posted on 2004-10-29
6
Medium Priority
?
194 Views
Last Modified: 2011-04-14
Hello,

I want to write an xml file on a button click.
Under the button I have

XmlTextWriter w = new XmlTextWriter("D:\\rich\\test.xml");
w.WriteStartElement("x","root","urn:1");
w.WriteStartElement("y","item","urn:1");
w.WriteEndElement();
w.WriteEndElement();
w.Close();

but I get an error message saying that w cannot be destroyed. I got this code from the ms web stie and cannot work out why it is saying it.

I can write a blank empty file by
CreateFile(D:\\rich\\test.xml, FILE_WRITE_DATA, FILE_SHARE_READ, NULL, CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
but I need it to contain some xml dependent on the options selected in my MFC form

Thanks in advance

Richard
0
Comment
Question by:richjo100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 12444655
Try w.Flush() before w.Close()
0
 

Author Comment

by:richjo100
ID: 12451087
Hi nonubik,
I'll try that over the next couple of days. I was wondering if it was to do with the scope of my declaration. Should I declare the xmltextwriter outside of my button click?
0
 

Author Comment

by:richjo100
ID: 12464046
Hi nonubik. I tried the w.Flush() and it didnt work
0
 

Author Comment

by:richjo100
ID: 12464582
Worked it out. I think I was getting confused with C# and c++

String* path = new String("D:/rich/test.xml");
XmlTextWriter* w =new XmlTextWriter(path, 0);                   
w->WriteStartElement("MetaData");
w->WriteAttributeString("Tracks", "V");
w->WriteAttributeString("Logged", "1");
w->WriteEndElement();
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12735535
PAQed with points refunded (100)

modulo
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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