public void XMLWriter(string p_sXMLPath, Dictionary <string, string> DXMLConfig) { StringBuilder sb = new StringBuilder(); //using(XmlWriter xwr = XmlWriter.Create(p_sXMLPath)) using (XmlWriter xwr = XmlWriter.Create(sb)) { xwr.WriteStartDocument(); xwr.WriteStartElement("SETTING"); xwr.WriteAttributeString("ID", "XML001"); xwr.WriteElementString(_TICK, DXMLConfig[_TICK]); xwr.WriteElementString(_TOTAL, DXMLConfig[_TOTAL]); xwr.WriteElementString(_LEVEL_1, DXMLConfig[_LEVEL_1]); xwr.WriteElementString(_LEVEL_3, DXMLConfig[_LEVEL_3]); xwr.WriteElementString(_LEVEL_50, DXMLConfig[_LEVEL_50]); xwr.WriteEndElement(); xwr.WriteEndDocument(); } string sRijndaelText = CRijndael.EncryptString(sb.ToString(), CRijndael._bKey); File.WriteAllText(p_sXMLPath, sRijndaelText); }
public Dictionary <string, string> XMLReader(string p_sXMLReader) { string sRijndaelText = File.ReadAllText(p_sXMLReader); string sDecText = CRijndael.DecryptString(sRijndaelText, CRijndael._bKey); Dictionary <string, string> DXMLConfig = new Dictionary <string, string>(); using (XmlReader rd = XmlReader.Create(new StringReader(sDecText))) { while (rd.Read()) { if (rd.IsStartElement()) { if (rd.Name.Equals("SETTING")) { string sTempID = rd["ID"]; rd.Read(); string sTempTick = rd.ReadElementContentAsString(_TICK, ""); DXMLConfig.Add(_TICK, sTempTick); string sTempTotal = rd.ReadElementContentAsString(_TOTAL, ""); DXMLConfig.Add(_TOTAL, sTempTotal); string sTempLevel1 = rd.ReadElementContentAsString(_LEVEL_1, ""); DXMLConfig.Add(_LEVEL_1, sTempLevel1); string sTempLevel3 = rd.ReadElementContentAsString(_LEVEL_3, ""); DXMLConfig.Add(_LEVEL_3, sTempLevel3); string sTempLevel50 = rd.ReadElementContentAsString(_LEVEL_50, ""); DXMLConfig.Add(_LEVEL_50, sTempLevel50); } } } } return(DXMLConfig); }