public bool Write(Document document, string pathDocument) { XmlDocument _document = XmlHelper.GetXmlDocumentFromDocument(document); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); XmlSerializer formatter = new XmlSerializer(typeof(XmlDocument)); XmlWriterSettings xmlWriterSettings = new System.Xml.XmlWriterSettings() { CloseOutput = false, Encoding = Encoding.UTF8, OmitXmlDeclaration = false, Indent = true }; using (FileStream fs = new FileStream(pathDocument, FileMode.OpenOrCreate)) { using (var wrXml = XmlWriter.Create(fs, xmlWriterSettings)) { formatter.Serialize(wrXml, _document, ns); } } return(true); }
public Document Read(string pathDocument) { XmlDocument _document = new XmlDocument(); _document.Cars = new List <XmlCar>(); XmlSerializer formatter = new XmlSerializer(typeof(XmlDocument)); using (FileStream fs = new FileStream(pathDocument, FileMode.OpenOrCreate)) { _document = (XmlDocument)formatter.Deserialize(fs); } Document document = _document.GetDocument(); return(document); }