Write XML DOM
#include "stdafx.h" using namespace System; using namespace System::Xml; XmlElement ^CreateMonster(XmlDocument ^doc){ XmlElement ^skeleton = doc->CreateElement("M"); XmlElement ^name = doc->CreateElement("N"); name->AppendChild(doc->CreateTextNode("S")); skeleton->AppendChild(name); XmlElement ^hitdice = doc->CreateElement("H"); XmlAttribute ^att = doc->CreateAttribute("D"); att->Value = "1"; hitdice->Attributes->Append(att); att = doc->CreateAttribute("Default"); att->Value = "3"; hitdice->Attributes->Append(att); skeleton->AppendChild(hitdice); XmlElement ^weapon = doc->CreateElement("W"); att = doc->CreateAttribute("N"); att->Value = "2"; weapon->Attributes->Append(att); att = doc->CreateAttribute("D"); att->Value = "1"; weapon->Attributes->Append(att); weapon->AppendChild(doc->CreateTextNode("C")); skeleton->AppendChild(weapon); return skeleton; } void main() { XmlDocument ^doc = gcnew XmlDocument(); try { doc->Load("a.xml"); XmlNode ^root = doc->DocumentElement; XmlNode ^child = root->FirstChild->NextSibling; root->InsertAfter(CreateMonster(doc), child); doc->Save("New.xml"); } catch (Exception ^e) { Console::WriteLine("Error Occurred: {0}", e->Message ); } }