CppWriter.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:3k
源码类别:

.net编程

开发平台:

Visual C++

  1. // This is the main project file for VC++ application project 
  2. // generated using an Application Wizard.
  3. #include "stdafx.h"
  4. #using <mscorlib.dll>
  5. #using <System.xml.dll>
  6. using namespace System;
  7. using namespace System::Xml;
  8. // This is the entry point for this application
  9. #ifdef _UNICODE
  10. int wmain(void)
  11. #else
  12. int main(int argc, char* argv[])
  13. #endif
  14. {
  15.     // Check for required arguments
  16.     if (argc < 2)
  17.     {
  18.         Console::WriteLine(S"Usage: CppWriter path");
  19.         return -1;
  20.     }
  21.     String* path = new String(argv[1]);
  22.     try
  23.     {
  24.         // Create the writer...
  25.         // Use the default encoding
  26.         XmlTextWriter* writer = new XmlTextWriter(path, 0);
  27.         // Set the formatting
  28.         writer->Formatting = Formatting::Indented;
  29.         // Write the standard document start
  30.         writer->WriteStartDocument();
  31.         // Write the start of the root element
  32.         writer->WriteStartElement("geology");
  33.         // Start the volcano element
  34.         writer->WriteStartElement("volcano");
  35.         // Do the name attribute
  36.         writer->WriteAttributeString("name", "Mount St.Helens");
  37.         // Write the location element
  38.         writer->WriteStartElement("location");
  39.         writer->WriteString(S"Washington State, USA");
  40.         writer->WriteEndElement();
  41.         // Write the height element
  42.         writer->WriteStartElement("height");
  43.         writer->WriteAttributeString("value", "9677");
  44.         writer->WriteAttributeString("unit", "ft");
  45.         writer->WriteEndElement();
  46.         // Write the type element
  47.         writer->WriteStartElement("type");
  48.         writer->WriteString(S"stratovolcano");
  49.         writer->WriteEndElement();
  50.         // Write the eruption elements
  51.         writer->WriteStartElement("eruption");
  52.         writer->WriteString(S"1857");
  53.         writer->WriteEndElement();
  54.         writer->WriteStartElement("eruption");
  55.         writer->WriteString(S"1980");
  56.         writer->WriteEndElement();
  57.         // Write the magma element
  58.         writer->WriteStartElement("magma");
  59.         writer->WriteString(S"basalt, andesite and dacite");
  60.         writer->WriteEndElement();
  61.         // Close the volcano element
  62.         writer->WriteEndElement();
  63.         // Close the root element
  64.         writer->WriteEndElement();
  65.         // Flush and close
  66.         writer->Flush();
  67.         writer->Close();
  68.     }
  69.     catch (Exception* pe)
  70.     {
  71.         Console::WriteLine(pe->ToString());
  72.     }
  73.     return 0;
  74. }