locked
Epilog o.O RRS feed

  • Question

  • The class

    public ref class Solution
    {
    	String ^ Name;
    	String ^ File;
    	String ^ Folder;
    
    	public: DateTime DateCreated;
    	public: DateTime DateModified;
    
    	public: String ^ Description;
    
    	static System::Collections::Generic::List<Project^>^ Projects = gcnew System::Collections::Generic::List<Project^>();
    
    public:
    	Solution(String^_Name,String^_File,String ^ _Folder,String ^ _Description)
    	{
    		Name = _Name;
    		File = _File;
    		Folder = _Folder;
    		Description = _Description;
    
    		DateCreated = DateTime::Now;
    		DateModified = DateTime::Now;
    		if(!Directory::Exists(Folder))
    		{
    			Directory::CreateDirectory(Folder);
    		}
    		SaveSolution();
    	}
    	void AddProject(Project ^ prj)
    	{
    		Projects->Add(prj);
    	}
    	void RemoveProject(Project ^ prj)
    	{
    		Projects->Remove(prj);
    	}
    	void SaveSolution()
    	{
    		XmlTextWriter ^SolutionXMLWriter = gcnew XmlTextWriter(Folder + "\\" + File + ".sln", Encoding::UTF8);		
    		SolutionXMLWriter->WriteStartDocument();
    
    			//Solution Info
    			/*SolutionXMLWriter->WriteStartElement(L"Solution Version");
    					SolutionXMLWriter->WriteValue(SOLUTION_VERSION);	
    			SolutionXMLWriter->WriteEndElement();*/
    			//Projects
    			SolutionXMLWriter->WriteStartElement(L"Solution Info");
    				SolutionXMLWriter->WriteElementString(L"CreationDate",DateCreated.ToString("dd::mm::yyyy-hh::mm::ss"));
    				SolutionXMLWriter->WriteElementString(L"ModifiedDate",DateModified.ToString("dd::mm::yyyy-hh::mm::ss"));
    				SolutionXMLWriter->WriteElementString(L"Description",Description);
    				SolutionXMLWriter->WriteElementString(L"Folder",Folder);
    				SolutionXMLWriter->WriteElementString(L"File",File);
    			SolutionXMLWriter->WriteEndElement();
    			SolutionXMLWriter->WriteStartElement(L"Projects");
    				for each(Project^ prj in Projects )
    				{
    					SolutionXMLWriter->WriteStartElement(L"Project");
    						SolutionXMLWriter->WriteElementString(L"File",prj->GetPath());
    						SolutionXMLWriter->WriteElementString(L"Description",prj->Description);
    							SolutionXMLWriter->WriteStartElement(L"Open");
    								SolutionXMLWriter->WriteValue(prj->Open);
    							SolutionXMLWriter->WriteEndElement();
    							SolutionXMLWriter->WriteStartElement(L"Export");
    								SolutionXMLWriter->WriteValue(prj->IsExportAble);
    							SolutionXMLWriter->WriteEndElement();
    					SolutionXMLWriter->WriteEndElement();
    				}
    			SolutionXMLWriter->WriteEndElement();
    
    		SolutionXMLWriter->WriteEndDocument();
    		SolutionXMLWriter->Flush();
    		SolutionXMLWriter->Close();
    	}
    };

    Error Line showed by VS10

    Solution ^ temp = gcnew Solution(Textbox_Name->Text,Textbox_Name->Text,ComboBox_Location->Text,"");	

    The error

    An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

    Additional information: Token StartElement in state Epilog would result in an invalid XML document.

    The first 2 words written by beginners "Hello, World". #include<brain.h> :)

    Tuesday, June 4, 2013 12:14 PM

Answers

  • You have more than one element at the root level.    You need to wrap the whole thing in some toplevel WriteStartElement/WriteEndElement.

    Also, while this is not your problem, you do understand that in C++ an access specifier applies to all the members that follow until another one is encountered..

    That is, the ones on the Description and DateModified lines are redundant and the static Projects member has public access not private.

    Tuesday, June 4, 2013 12:36 PM