Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 using System;
00040 using System.IO;
00041 using System.Xml;
00042 using System.Text;
00043
00044 namespace XMLStorage
00045 {
00046
00047
00048
00049
00050 public class XMLDoc : XMLNode
00051 {
00052 public XMLHeader _header = new XMLHeader();
00053
00054 public XMLDoc()
00055 : base("")
00056 {
00057 }
00058
00059 public XMLDoc(string path, XmlReaderSettings xmlSettings=null)
00060 : base("")
00061 {
00062 readFile(path, xmlSettings);
00063 }
00064
00065 public void readFile(string path, XmlReaderSettings xmlSettings=null)
00066 {
00067 read(new StreamReader(path), xmlSettings);
00068 }
00069
00070 public void read(TextReader reader, XmlReaderSettings xmlSettings=null)
00071 {
00072 XMLDocReader docReader = new XMLDocReader(this);
00073
00074 docReader.read(reader, xmlSettings);
00075
00076 _header._additional = docReader.getInstructions();
00077 }
00078
00079
00080 public override void write(TextWriter w)
00081 {
00082 write(w, WRITE_MODE.FORMAT_SMART);
00083 }
00084
00085
00086
00087 public override void write(TextWriter w, WRITE_MODE mode)
00088 {
00089 _header.print(w);
00090
00091 if (_children.Count == 1)
00092 _children.First.Value.write(w, mode);
00093 else if (_children.Count > 0)
00094 throw new Exception("more than one XML root entry");
00095 }
00096
00097
00098 public void writeFormating(TextWriter w)
00099 {
00100 write(w, WRITE_MODE.FORMAT_PRETTY);
00101 }
00102
00103 public void writeFile(string path)
00104 {
00105 writeFile(path, WRITE_MODE.FORMAT_SMART);
00106 }
00107
00108 public void writeFile(string path, WRITE_MODE mode)
00109 {
00110 string encoding = _header._encoding.Length>0? _header._encoding: "UTF-8";
00111
00112 TextWriter w = new StreamWriter(path, false, Encoding.GetEncoding(encoding));
00113
00114 try {
00115 write(w, mode);
00116 } finally {
00117 w.Close();
00118 }
00119 }
00120
00121 public void writeFormating(string path)
00122 {
00123 TextWriter w = new StreamWriter(path, false, Encoding.UTF8);
00124
00125 try {
00126 writeFormating(w);
00127 } finally {
00128 w.Close();
00129 }
00130 }
00131 }
00132
00133 }