richjo100
asked on
Writing xml with mfc app
Hello,
I want to write an xml file on a button click.
Under the button I have
XmlTextWriter w = new XmlTextWriter("D:\\rich\\t est.xml");
w.WriteStartElement("x","r oot","urn: 1");
w.WriteStartElement("y","i tem","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,NUL L);
but I need it to contain some xml dependent on the options selected in my MFC form
Thanks in advance
Richard
I want to write an xml file on a button click.
Under the button I have
XmlTextWriter w = new XmlTextWriter("D:\\rich\\t
w.WriteStartElement("x","r
w.WriteStartElement("y","i
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.
but I need it to contain some xml dependent on the options selected in my MFC form
Thanks in advance
Richard
Try w.Flush() before w.Close()
ASKER
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?
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?
ASKER
Hi nonubik. I tried the w.Flush() and it didnt work
ASKER
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("Meta Data");
w->WriteAttributeString("T racks", "V");
w->WriteAttributeString("L ogged", "1");
w->WriteEndElement();
String* path = new String("D:/rich/test.xml")
XmlTextWriter* w =new XmlTextWriter(path, 0);
w->WriteStartElement("Meta
w->WriteAttributeString("T
w->WriteAttributeString("L
w->WriteEndElement();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.