![]() |
|
This page explains how to write XML data to a file in Visual C++ .NET,
with
Shown below is the flow of the procedure to write XML data to a file.
First, construct the
XmlTextWriter* pWriter;
try
{
pWriter = new XmlTextWriter (fileName, NULL);
pWriter->Formatting = Formatting::Indented;
pWriter->WriteStartDocument(true);
//write the elements to the file
pWriter->Flush();
pWriter->Close();
}
catch (Exception* e)
{
Console::WriteLine (S"Exception: {0}", e->ToString());
}
__finally
{
if (pWriter != 0)
pWriter->Close();
}
Start writing the node with
pWriter->WriteStartElement("labels");
...
pWriter->WriteEndElement();
| ||
|
If the node is a leaf that has no sub-tree nor sub-elements call
pWriter->WriteElementString(S"image", S"Gladiolus.jpg");
According to the XML guideline, the text not to be exposed to users
should be specified as attributes, such as color or type face. To add
an attribute to the node, call
pWriter->WriteAttributeString(S"color", S"blue");
Erica Asai Last Modified: Fri Dec 02 02:49:52 2005
|