1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __C_XML_WRITER_H_INCLUDED__
6 #define __C_XML_WRITER_H_INCLUDED__
7 
8 #include <wchar.h>
9 #include "IXMLWriter.h"
10 #include "IWriteFile.h"
11 
12 namespace irr
13 {
14 namespace io
15 {
16 
17 	//! Interface providing methods for making it easier to write XML files.
18 	class CXMLWriter : public IXMLWriter
19 	{
20 	public:
21 
22 		//! Constructor
23 		CXMLWriter(IWriteFile* file);
24 
25 		//! Destructor
26 		virtual ~CXMLWriter();
27 
28 		//! Writes a xml 1.0 header like <?xml version="1.0"?>
29 		virtual void writeXMLHeader();
30 
31 		//! Writes an xml element with maximal 5 attributes
32 		virtual void writeElement(const wchar_t* name, bool empty=false,
33 			const wchar_t* attr1Name = 0, const wchar_t* attr1Value = 0,
34 			const wchar_t* attr2Name = 0, const wchar_t* attr2Value = 0,
35 			const wchar_t* attr3Name = 0, const wchar_t* attr3Value = 0,
36 			const wchar_t* attr4Name = 0, const wchar_t* attr4Value = 0,
37 			const wchar_t* attr5Name = 0, const wchar_t* attr5Value = 0);
38 
39 		//! Writes an xml element with any number of attributes
40 		virtual void writeElement(const wchar_t* name, bool empty,
41 				core::array<core::stringw> &names, core::array<core::stringw> &values);
42 
43 		//! Writes a comment into the xml file
44 		virtual void writeComment(const wchar_t* comment);
45 
46 		//! Writes the closing tag for an element. Like </foo>
47 		virtual void writeClosingTag(const wchar_t* name);
48 
49 		//! Writes a text into the file. All occurrences of special characters like
50 		//! & (&amp;), < (&lt;), > (&gt;), and " (&quot;) are automaticly replaced.
51 		virtual void writeText(const wchar_t* text);
52 
53 		//! Writes a line break
54 		virtual void writeLineBreak();
55 
56 		struct XMLSpecialCharacters
57 		{
58 			wchar_t Character;
59 			const wchar_t* Symbol;
60 		};
61 
62 	private:
63 
64 		void writeAttribute(const wchar_t* att, const wchar_t* name);
65 
66 		IWriteFile* File;
67 		s32 Tabs;
68 
69 		bool TextWrittenLast;
70 	};
71 
72 } // end namespace irr
73 } // end namespace io
74 
75 #endif
76 
77