XmlWriterSettings not working

Mar 22, 2011 at 6:31pm
Hi guys,

Was wondering if anyone could point me in the right direction with my issue here. The code below when compiled gives the following error syntax error: identifier 'Create'.

Every example i find on the web uses this format to define the settings for the XmlWriter. I can get around the problem without using create but then the XML generated is not indented which it needs to be.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
void Form1::SaveHashButton()
{
	try
	{
		XmlWriterSettings^ settings = gcnew XmlWriterSettings();
		settings->NewLineOnAttributes = true;
		settings->Indent = true;

		XmlWriter^ Writer = gcnew XmlTextWriter::Create("XMLTesting.xml", settings);
		
		Writer->WriteStartDocument();

		Writer->WriteStartElement("Project");
		Writer->WriteAttributeString("Name", textBox1->Text->ToString());

		Writer->WriteStartElement("TestCycle");
		Writer->WriteAttributeString("#", textBox2->Text->ToString());

		for each(String^ FileName in listBox2->Items)
		{
			Writer->WriteStartElement("FileName");
			Writer->WriteString(FileName);
			
			//End the FileName element
			Writer->WriteEndElement();

			for each(String^ Hash in listBox3->Items)
			{
				Writer->WriteStartElement("HashCode");
				Writer->WriteString(Hash);

				//End the HashCode element
				Writer->WriteEndElement();
			}
		}
		
		//End Element for TestCycle
		Writer->WriteEndElement();
		//End element for Project
		Writer->WriteEndElement();

		Writer->Flush();
		Writer->Close();
	}
	catch (Exception^ e)
	{
		MessageBox::Show(e->ToString());
	}
}


Please if anyone can help it would be much appreciated.

Thanks
Mar 24, 2011 at 2:57pm
Ok, it's not C++ but...

I suspect that gcnew on line 9 is wrong. Remove it and see what happens
Mar 24, 2011 at 6:07pm
Is that not just managed C++?
Last edited on Mar 24, 2011 at 6:08pm
Mar 25, 2011 at 11:00pm
Removing the gcnew worked, thanks coder777
Topic archived. No new replies allowed.