Question

I wrote this code:

            XmlTextWriter^ w = gcnew XmlTextWriter( fs, nullptr );
        w->WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
        w->WriteStartElement("healing");
            w->WriteStartElement("health1");
                w->WriteElementString("value", "100");
                w->WriteElementString("hotkey", "2");
                w->WriteElementString("enable", "0");
            w->WriteEndElement();
            w->WriteStartElement("health2");
                w->WriteElementString("value", "100");
                w->WriteElementString("hotkey", "2");
                w->WriteElementString("enable", "0");
            w->WriteEndElement();
            w->WriteStartElement("health3");
                w->WriteElementString("value", "100");
                w->WriteElementString("hotkey", "2");
                w->WriteElementString("enable", "0");
            w->WriteEndElement();
            w->WriteStartElement("mana");
                w->WriteElementString("value", "100");
                w->WriteElementString("hotkey", "2");
                w->WriteElementString("enable", "0");
            w->WriteEndElement();
        w->WriteEndElement();
        w->Flush();
        w->Close();

But it's creating XML which is not pretty looking, without enter, tabs etc:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><healing><health1><value>100</value><hotkey>2</hotkey><enable>0</enable></health1><health2><value>100</value><hotkey>2</hotkey><enable>0</enable></health2><health3><value>100</value><hotkey>2</hotkey><enable>0</enable></health3><mana><value>100</value><hotkey>2</hotkey><enable>0</enable></mana></healing>

How can I make it look pretty?

Was it helpful?

Solution

Probably you want to set the Formatting property on the XmlTextWriter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top