Solved

Writing xml with mfc app

Posted on 2004-10-29
169 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
Question by:richjo100
    5 Comments
     
    LVL 16

    Expert Comment

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

    Author Comment

    by:richjo100
    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
    Hi nonubik. I tried the w.Flush() and it didnt work
    0
     

    Author Comment

    by:richjo100
    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:
    PAQed with points refunded (100)

    modulo
    Community Support Moderator
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    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…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

    913 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

    16 Experts available now in Live!

    Get 1:1 Help Now