CppWriter.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:3k
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #using <mscorlib.dll>
- #using <System.xml.dll>
- using namespace System;
- using namespace System::Xml;
- // This is the entry point for this application
- #ifdef _UNICODE
- int wmain(void)
- #else
- int main(int argc, char* argv[])
- #endif
- {
- // Check for required arguments
- if (argc < 2)
- {
- Console::WriteLine(S"Usage: CppWriter path");
- return -1;
- }
- String* path = new String(argv[1]);
- try
- {
- // Create the writer...
- // Use the default encoding
- XmlTextWriter* writer = new XmlTextWriter(path, 0);
- // Set the formatting
- writer->Formatting = Formatting::Indented;
- // Write the standard document start
- writer->WriteStartDocument();
- // Write the start of the root element
- writer->WriteStartElement("geology");
- // Start the volcano element
- writer->WriteStartElement("volcano");
- // Do the name attribute
- writer->WriteAttributeString("name", "Mount St.Helens");
- // Write the location element
- writer->WriteStartElement("location");
- writer->WriteString(S"Washington State, USA");
- writer->WriteEndElement();
- // Write the height element
- writer->WriteStartElement("height");
- writer->WriteAttributeString("value", "9677");
- writer->WriteAttributeString("unit", "ft");
- writer->WriteEndElement();
- // Write the type element
- writer->WriteStartElement("type");
- writer->WriteString(S"stratovolcano");
- writer->WriteEndElement();
- // Write the eruption elements
- writer->WriteStartElement("eruption");
- writer->WriteString(S"1857");
- writer->WriteEndElement();
- writer->WriteStartElement("eruption");
- writer->WriteString(S"1980");
- writer->WriteEndElement();
- // Write the magma element
- writer->WriteStartElement("magma");
- writer->WriteString(S"basalt, andesite and dacite");
- writer->WriteEndElement();
- // Close the volcano element
- writer->WriteEndElement();
- // Close the root element
- writer->WriteEndElement();
- // Flush and close
- writer->Flush();
- writer->Close();
- }
- catch (Exception* pe)
- {
- Console::WriteLine(pe->ToString());
- }
- return 0;
- }