/// <summary> /// Loads the specified path. /// </summary> /// <param name="path">The path.</param> public void Load(string path) { try { CommandsMap.Clear(); document.RemoveAll(); document.Load(path); var root = document.SelectSingleNode("/Commands"); var commandNodes = root.ChildNodes; foreach (XmlNode commandNode in commandNodes) { var name = commandNode.Attributes["name"].Value; var content = commandNode.Attributes["content"].Value; var regex = new Regex(commandNode.Attributes[2].Value); var type = EnumExtensions .GetValueFromDescription <Command.TypeE>(commandNode.Attributes["type"].Value); var description = commandNode.FirstChild.InnerText; CommandsMap.Add(Command.CreateCommand(name, content, description, regex, type)); } FilePath = path; } catch { Console.Error.WriteLine("Could not load command list into memory"); MissingFileManager.CreateCommandsFile(); Load(MissingFileManager.DEFAULT_COMMANDS_PATH); } }
//Save 함수 - Root 지정 private void Save_Root(string Name) { xmlFile.RemoveAll(); xmlFile.AppendChild(xmlFile.CreateXmlDeclaration("1.0", "UTF-8", "yes")); rootNode = xmlFile.CreateNode(XmlNodeType.Element, Name, string.Empty); xmlFile.AppendChild(rootNode); }
/* * XMLUnit(string XMLFilePath) * { * this.XMLFilePath = XMLFilePath; * try * { * xDoc = new XmlDocument(); * xDoc.Load(XMLFilePath); * * } * catch (Exception ex) * { * Log.WriteLog("XMLUnit", "Error", "创建XmlDocument失败:" + ex.Message); * } * } * */ /************************************************************************ * Function: Get Value of The Key * IN: string XMLFilePath, XML File Path * string RootNode, Root Node * string Section, Section of key * string Key, Key to Get Value * OUT: string * Author: DQS * Date: 2012-08-23 ************************************************************************/ public static string XmlGetValue(string XMLFilePath, string RootNode, string Section, string Key) { string Value = ""; try { if (File.Exists(XMLFilePath)) { xDoc.Load(XMLFilePath); XmlNodeList nodeList; XmlNode root = xDoc.SelectSingleNode(RootNode); nodeList = root.SelectNodes(Section + "/" + Key); foreach (XmlNode node in nodeList) { // if (Key == node.Name) Value = node.InnerText.ToString(); break; } } else { return(Value); } } catch (Exception ex) { //Log.WriteLog("XMLUnit", "Error", "读取参数" + Key + "失败:" + ex.Message); } finally { xDoc.RemoveAll(); // xDoc = null; } return(Value); }
public void ResolveEntity2() { document.RemoveAll(); string ent1 = "<!ENTITY ent 'entity string'>"; string ent2 = "<!ENTITY ent2 '<foo/><foo/>'>]>"; string dtd = "<!DOCTYPE root[<!ELEMENT root (#PCDATA|foo)*>" + ent1 + ent2; string xml = dtd + "<root>&ent3;&ent2;</root>"; XmlTextReader xtr = new XmlTextReader(xml, XmlNodeType.Document, null); xtr.Read(); document.AppendChild(document.ReadNode(xtr)); document.AppendChild(document.ReadNode(xtr)); xtr.Close(); Assert.AreEqual(xml, document.OuterXml); XmlNodeReader nr = new XmlNodeReader(document); nr.Read(); // DTD nr.Read(); // root nr.Read(); // &ent3; Assert.AreEqual(XmlNodeType.EntityReference, nr.NodeType); // ent3 does not exist in this dtd. nr.ResolveEntity(); Assert.AreEqual(XmlNodeType.EntityReference, nr.NodeType); nr.Read(); #if false // Hmm... MS.NET returned as it is a Text node. Assert.AreEqual(XmlNodeType.Text, nr.NodeType); Assert.AreEqual(String.Empty, nr.Value); nr.Read(); // Really!? Assert.AreEqual(XmlNodeType.EndEntity, nr.NodeType); Assert.AreEqual(String.Empty, nr.Value); #endif }
/// <summary> /// Экспорт списка процессов в файл формата XML /// </summary> /// <param name="processes">Список процессов</param> public void Export(IEnumerable <IProcess> processes) { _xmlDocument.RemoveAll(); var root = _xmlDocument.CreateElement("Processes"); // Создание структуры XML, отражающей структуру класса Process foreach (var process in processes) { var procNode = _xmlDocument.CreateElement("Process"); var nameNode = _xmlDocument.CreateElement("Name"); var actsNode = _xmlDocument.CreateElement("Actions"); // Привязка значений полей и свойств процесса соостветствующим полям документа nameNode.InnerText = process.Name; procNode.AppendChild(nameNode); Actions2Xml(actsNode, process.Actions); procNode.AppendChild(actsNode); root.AppendChild(procNode); _xmlDocument.AppendChild(root); try { _xmlDocument.Save(string.Format("{0}.xml", process.Name)); } catch (Exception exception) { throw new IOException("Some troubles: " + exception.Message); } } }
// TODO: Move to session /// <summary> /// Loads the commands. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> public ISet <Command> LoadCommands(string path = DEFAULT_COMMANDS_PATH) { if (null == commands) { commands = new HashSet <Command>(); } try { commands.Clear(); document.RemoveAll(); document.Load(DEFAULT_COMMANDS_PATH); var root = document.SelectSingleNode("/Commands"); var commandNodes = root.ChildNodes; foreach (XmlNode commandNode in commandNodes) { var name = commandNode.Attributes[0].Value; var content = commandNode.Attributes[1].Value; var regex = new Regex(commandNode.Attributes[2].Value); var type = EnumExtensions .GetValueFromDescription <Command.TypeE>(commandNode.Attributes[3].Value); var description = commandNode.FirstChild.InnerText; commands.Add(Command.CreateCommand(name, content, description, regex, type)); } } catch { Console.Error.WriteLine("Could not load command list into memory"); } return(commands); }
/// <summary> /// Loads a behaviour from the given filename /// </summary> /// <param name="getBehaviorNode">The callback used to return the behavior.</param> public override void Load(List <Nodes.Node.ErrorCheck> result, GetBehaviorNode getBehaviorNode) { try { //FileStream fs = Plugin.ConcurrentSourceFileStreams.GetValueUnsafe(_filename); //if (fs == null) //{ // fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); //} FileStream fs = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); _xmlfile.Load(fs); fs.Close(); XmlNode rootNode = _xmlfile.ChildNodes[1]; int versionLoaded = (rootNode.Attributes != null) ? int.Parse(rootNode.Attributes["Version"] != null ? rootNode.Attributes["Version"].Value : "0") : 0; this._version = versionLoaded; if (versionLoaded > Nodes.Behavior.NewVersion) { MessageBox.Show(Resources.FileVersionWarning, Resources.LoadWarning, MessageBoxButtons.OK); } foreach (XmlNode xmlNode in rootNode.ChildNodes) { if (xmlNode.Name == "Node") { _behavior = (BehaviorNode)CreateNodeAndAdd(result, getBehaviorNode, xmlNode, null, null); ProcessedBehaviors processedBehaviors = new ProcessedBehaviors(); DoPostLoad(processedBehaviors, (Node)_behavior); break; } } if (_behavior != null) { if (versionLoaded != Nodes.Behavior.NewVersion) { _behavior.Version = Nodes.Behavior.NewVersion; _behavior.TriggerWasModified((Node)_behavior); } string noError = rootNode.Attributes["NoError"] != null ? rootNode.Attributes["NoError"].Value : "false"; _behavior.HasNoError = (noError == "true"); } } catch (Exception e) { string errorInfo = string.Format("{0}\n{1}", _filename, e.Message); MessageBox.Show(errorInfo, Resources.LoadError, MessageBoxButtons.OK); _xmlfile.RemoveAll(); throw; } }
public void iniciar() { docXML.RemoveAll(); tNodoSeleccionadoClipboard = null; lngIDMax = 0; mRutaFicheroXML = ""; mRutaFicheroXMLNombre = ""; mRutaFicheroXMLRuta = ""; mRepositorio = ""; }
/// <summary> /// Deaktiviert das übergebene Profil auf Dateiebene /// </summary> /// <param name="p"></param> public void setProfileInactive(Profile p) { if (File.Exists(p.ProfilePath)) { xmlDocFanConfig.RemoveAll(); xmlDocFanConfig.Load(p.ProfilePath); xmlDocFanConfig.DocumentElement.Attributes["active"].Value = "False"; xmlDocFanConfig.Save(p.ProfilePath); } }
private void openDefinitionButton_Click(object sender, EventArgs e) { if (definitionOpenDialog.ShowDialog() != DialogResult.Cancel) { string def = definitionOpenDialog.FileName; rootDirTextBox.Text = Path.GetDirectoryName(def); XmlDocument doc = new XmlDocument(); doc.Load(def); XmlNodeList list = doc.GetElementsByTagName("proxygen"); string relPath = list.Item(0).Attributes["definitionsrc"].Value; proxydefPathTextBox.Text = Path.Combine(rootDirTextBox.Text, relPath); doc.RemoveAll(); doc = null; if (!ValidateTemplatePaths()) { proxydefPathTextBox.Text = string.Empty; rootDirTextBox.Text = string.Empty; MessageBox.Show("Template contains an invalid image path"); } else { generateProxyButton.Enabled = true; } } }
public void GetXml(string url, string sFile, string parameter) { StopCoroutine("RetrievingData"); sLastURL = sFile; if (_xml_loading != null) { _xml_loading.Dispose(); _xml_loading = null; } string sUrlTarget = url + sFile + "?" + parameter; //if (Application.platform == RuntimePlatform.IPhonePlayer) // sUrlTarget = System.Uri.EscapeUriString (sUrlTarget); //GUI_Debug.Log("[WWW_XML] GetXml : '"+sUrlTarget+"'"); _xml_loading = new WWW(sUrlTarget); if (_xmlDoc != null) { _xmlDoc.RemoveAll(); _xmlDoc = null; } bDownloading = true; StartCoroutine(RetrievingData()); }
private static string UnixFallbackStringValue(string key, string value) { var userName = Environment.UserName; foreach (var program in new List <string> { "paratext", "fieldworks" }) { var registryPath = "/home/" + userName + "/.config/" + program + "/registry/LocalMachine/software/"; var valueFile = Path.Combine(registryPath, key.ToLower(), "values.xml"); if (!File.Exists(valueFile)) { continue; } XDoc.RemoveAll(); var xr = XmlReader.Create(valueFile); XDoc.Load(xr); xr.Close(); var node = value != null?XDoc.SelectSingleNode("//*[@name='" + value + "']") : XDoc.DocumentElement; if (node != null) { return(node.InnerText); } } return(null); }
/// <summary> /// Get an XML document representing the <see cref="StudyXml"/>. /// </summary> /// <remarks> /// This method can be called multiple times as DICOM SOP Instances are added /// to the <see cref="StudyXml"/>. Note that caching is done of the /// XmlDocument to improve performance. If the collections in the InstanceStreams /// are modified, the caching mechanism may cause the updates not to be contained /// in the generated XmlDocument. /// </remarks> /// <returns></returns> public XmlDocument GetMemento(StudyXmlOutputSettings settings) { if (_doc == null) { _doc = new XmlDocument(); } else { _doc.RemoveAll(); } XmlElement clearCanvas = _doc.CreateElement("ClearCanvasStudyXml"); XmlElement study = _doc.CreateElement("Study"); XmlAttribute studyInstanceUid = _doc.CreateAttribute("UID"); studyInstanceUid.Value = _studyInstanceUid; study.Attributes.Append(studyInstanceUid); foreach (SeriesXml series in this) { XmlElement seriesElement = series.GetMemento(_doc, settings); study.AppendChild(seriesElement); } clearCanvas.AppendChild(study); _doc.AppendChild(clearCanvas); return(_doc); }
//清除 public void Clear() { InfoList.Clear(); InfoList = null; XML.RemoveAll(); XML = null; }
/// <summary> /// 读取XML数据 /// </summary> private void ReadXmlData() { //清理原有的 xmlPresmissionDoc.RemoveAll(); //根据路径将XML读取出来 xmlPresmissionDoc.Load(this.allLanguageFileFullName[this.CurChooseLanguageIndex]); if (this.chooseDatas == null) { this.chooseDatas = new List <QChooseData>(); this.allPermissions = new Dictionary <string, XmlElement>(); } else { this.chooseDatas.Clear(); this.allPermissions.Clear(); } //获取Config的所有子节点 XmlNodeList nodeList = xmlPresmissionDoc.SelectSingleNode("Config").ChildNodes; foreach (XmlElement _xmlele in nodeList) { this.ShowAConfig(_xmlele, _xmlele.GetAttribute(StrIndex), _xmlele.GetAttribute(StrPermission), _xmlele.GetAttribute(StrDescription)); } }
private void btnNew_Click(object sender, EventArgs e) { bool bFind = Directory.Exists(ParamSetMgr.GetInstance().CurrentWorkDir); if (!bFind) { MessageBox.Show("没有产品文件,请设置", "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Form_Input form_Input = new Form_Input("产品名称"); if (DialogResult.OK == form_Input.ShowDialog()) { if (form_Input.InputText != "") { string str = ParamSetMgr.GetInstance().CurrentWorkDir + ("\\") + form_Input.InputText + ("\\") + form_Input.InputText + (".xml"); Directory.CreateDirectory(ParamSetMgr.GetInstance().CurrentWorkDir + ("\\") + form_Input.InputText); XmlDocument document = new XmlDocument(); XmlDeclaration dec = document.CreateXmlDeclaration("1.0", "utf-8", "no"); document.AppendChild(dec); XmlElement root = document.CreateElement("ParamCfg"); document.AppendChild(root); XmlElement item = document.CreateElement("ParamSet"); root.AppendChild(item); document.Save(str); treeView_ProdutFile.Nodes[1].Nodes.Add(form_Input.InputText); document.RemoveAll(); document = null; } } treeView_ProdutFile.Nodes[0].Expand(); }
/// <summary> /// Deserialize the object from xml. /// </summary> /// <param name="reader">The xml reader for reading the /// serialized xml.</param> public virtual void ReadXml(XmlReader reader) { XmlDocument doc = SerializationUtilities.LoadXml(reader.ReadOuterXml()); XmlNameTable xmlnt = doc.NameTable; XmlElement root = doc.CreateElement(XmlElementName, XmlNamespace); XmlNodeList xmlNodes = doc.DocumentElement.SelectNodes("*"); foreach (XmlNode node in xmlNodes) { root.AppendChild(node); } doc.RemoveAll(); doc.AppendChild(root); string contents = doc.OuterXml; foreach (string key in placeHolders.Keys) { if (placeHolders[key] != null) { contents = contents.Replace(placeHolders[key], key); } } Stub = SerializationUtilities.DeserializeFromXmlText(contents, Stub.GetType()); }
public void ReadData() { if (!App.IsConnectedToInternet()) { new Error("ישנה בעיה בחיבור לאינטרנט, לא ניתן להמשיך את השימוש בתוכנה.").ShowDialog(); return; } string way = ""; try { way = "A"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); way = "B"; request.UserAgent = "Alarm"; way = "C"; XmlDocument doc = new XmlDocument(); way = "D"; using (WebResponse response = request.GetResponse()) using (Stream rss = response.GetResponseStream()) { doc.Load(rss); rss.Close(); rss.Dispose(); response.Close(); } way = "E"; for (int i = 0; i < doc.ChildNodes.Count && rssNode == null; i++) { if (doc.ChildNodes[i].Name == "rss") { rssNode = doc.ChildNodes[i]; way = "F" + i; } } for (int i = 0; i < rssNode.ChildNodes.Count && channelNode == null; i++) { if (rssNode.ChildNodes[i].Name == "channel") { channelNode = rssNode.ChildNodes[i]; way = "G" + i; } } for (int i = 0; i < channelNode.ChildNodes.Count; i++) { if (channelNode.ChildNodes[i].Name == "item") { items.Add(channelNode.ChildNodes[i]); way = "H" + i; //if (last == null) last = channelNode.ChildNodes[i]; } } doc.RemoveAll(); request.Abort(); } catch { new Error("קיימת בעיה בעדכון תוכן, אם הבעיה מתמשכת פנה אלינו במייל: " + App.mail + "\r\n(קוד בעיה: " + way + ")").ShowDialog(); } }
public bool Save(String path) { Boolean Saved = true; XmlDocument m_Xdoc = new XmlDocument(); try { XmlNode Node; m_Xdoc.RemoveAll(); Node = m_Xdoc.CreateXmlDeclaration("1.0", "utf-8", String.Empty); m_Xdoc.AppendChild(Node); Node = m_Xdoc.CreateComment(String.Format(" Profile Configuration Data. {0} ", DateTime.Now)); m_Xdoc.AppendChild(Node); Node = m_Xdoc.CreateWhitespace("\r\n"); m_Xdoc.AppendChild(Node); Node = m_Xdoc.CreateNode(XmlNodeType.Element, "Profile", null); m_Xdoc.AppendChild(Node); m_Xdoc.Save(path); } catch { Saved = false; } return(Saved); }
public void WriteXML(string fileOut) { doc.RemoveAll(); doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); doc.AppendChild(root); doc.Save(fileOut); }
public void TestOASIS() { XmlDocument doc = new XmlDocument(); foreach (FileInfo fi in new DirectoryInfo(@"xml-test-suite/xmlconf/oasis").GetFiles("*.xml")) { try { if (fi.Name.IndexOf("fail") >= 0) { continue; } Console.WriteLine(fi.Name); XmlTextReader xtr = new XmlTextReader(fi.FullName); xtr.Namespaces = false; xtr.Normalization = true; doc.RemoveAll(); doc.Load(xtr); DumpDom(doc); } catch (XmlException ex) { if (fi.Name.IndexOf("pass") >= 0) { Console.WriteLine("Incorrectly invalid: " + fi.FullName + "\n" + ex.Message); } } } }
public static Dictionary <string, string> GetBlockSources(string path) { Dictionary <string, string> ret = new Dictionary <string, string>(); XmlDocument doc = new XmlDocument(); doc.Load(path); foreach (XmlNode node in doc.GetElementsByTagName("block")) { string id = node.Attributes["id"].Value; if (node.Attributes["src"] != null) { ret.Add(id, node.Attributes["src"].Value); } string fontPath = GetFontPath(node); if (fontPath != string.Empty) { ret.Add(id, fontPath); } } doc.RemoveAll(); doc = null; return(ret); }
private void UpdateXmlDocument() { xmlDocument.RemoveAll(); XmlNode root = xmlDocument.CreateElement(typeof(CLRDataItem).Name); xmlDocument.AppendChild(root); XmlElement stringProperty = xmlDocument.CreateElement("StringValue"); stringProperty.InnerText = StringValue; root.AppendChild(stringProperty); XmlElement intProperty = xmlDocument.CreateElement("IntegerValue"); intProperty.InnerText = IntegerValue.ToString(); root.AppendChild(intProperty); XmlAttribute boolAttribute = xmlDocument.CreateAttribute("BooleanValue"); boolAttribute.Value = BooleanValue.ToString(); root.Attributes.Append(boolAttribute); XmlAttribute doubleAttribute = xmlDocument.CreateAttribute("DoubleValue"); doubleAttribute.Value = DoubleValue.ToString(); root.Attributes.Append(doubleAttribute); XmlAttribute floatAttribute = xmlDocument.CreateAttribute("FloatValue"); floatAttribute.Value = FloatValue.ToString(); root.Attributes.Append(floatAttribute); }
private void SaveAsXML() { DataTable dt = (DataTable)bindingSource.DataSource; XmlDocument doc = new XmlDocument(); XmlNode rootNode = doc.CreateNode(XmlNodeType.Element, "root", null); foreach (DataRow row in dt.Rows) { object[] values = row.ItemArray; XmlNode prop = doc.CreateNode(XmlNodeType.Element, "propertyset", null); XmlNode name = doc.CreateNode(XmlNodeType.Element, "name", null); XmlNode value = doc.CreateNode(XmlNodeType.Element, "value", null); name.InnerText = (string)values[0]; value.InnerText = (string)values[1]; prop.AppendChild(name); prop.AppendChild(value); rootNode.AppendChild(prop); } doc.AppendChild(rootNode); string file = Path.Combine(GetExecutingDir(), xmlPropertyFileName); if (File.Exists(file)) { File.Delete(file); } doc.Save(file); doc.RemoveAll(); doc = null; }
/// <summary> /// 构造函数 /// </summary> private DNTCache() { if (MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached) { applyMemCached = true; } if (RedisConfigs.GetConfig() != null && RedisConfigs.GetConfig().ApplyRedis) { applyRedis = true; } if (applyMemCached || applyRedis) { try { cs = cachedStrategy = (ICacheStrategy)Activator.CreateInstance(Type.GetType("Discuz.EntLib." + (applyMemCached ? "MemCachedStrategy" : "RedisStrategy") + ", Discuz.EntLib", false, true)); } catch { throw new Exception("请检查Discuz.EntLib.dll文件是否被放置在bin目录下并配置正确"); } } else { cs = new DefaultCacheStrategy(); if (rootXml.HasChildNodes) { rootXml.RemoveAll(); } objectXmlMap = rootXml.CreateElement("Cache"); //建立内部XML文档. rootXml.AppendChild(objectXmlMap); } }
public static void WriteError(Exception ex, string fileName) { XmlDocument doc = new XmlDocument(); string strRootPath = System.Configuration.ConfigurationManager.AppSettings ["logfilepath"].ToString(); string xmlPath = System.Web.HttpContext.Current.Server.MapPath(strRootPath); doc.Load(@xmlPath); XmlNode newXMLNode, oldXMLNode; oldXMLNode = doc.ChildNodes[1].ChildNodes[0]; newXMLNode = oldXMLNode.CloneNode(true); StackTrace stackTrace = new StackTrace(); StackFrame stackFrame = stackTrace.GetFrame(1); MethodBase methodBase = stackFrame.GetMethod(); newXMLNode.ChildNodes[0].InnerText = DateTime.Now.ToString(); newXMLNode.ChildNodes[1].InnerText = fileName; newXMLNode.ChildNodes[2].InnerText = methodBase.DeclaringType.FullName; newXMLNode.ChildNodes[3].InnerText = methodBase.Name; newXMLNode.ChildNodes[4].InnerText = ex.TargetSite.Name; newXMLNode.ChildNodes[5].InnerText = ex.Message; newXMLNode.ChildNodes[6].InnerText = ex.StackTrace; newXMLNode.ChildNodes[7].InnerText = System.Web.HttpContext.Current.Request.UserHostAddress; newXMLNode.ChildNodes[8].InnerText = System.Web.HttpContext.Current.Request.Url.OriginalString; doc.ChildNodes[1].AppendChild(newXMLNode); doc.Save(@xmlPath); doc.RemoveAll(); }
private void saveSkills()//保存技能数据伟XML文档 { inactiveSkillXml.RemoveAll(); inActiveSkillElement.RemoveAll(); for (int i = 0; i < allSkillDrags.Length; i++) { if (i < 6)//前六个应用到界面 { skills_OnUI_Pos[i] = i; skills_OnUI[i] = allSkillDrags[i].thisSkill; } else//后六个存储为XML { if (allSkillDrags[i].existSkill)//如果有技能 { skill sk = allSkillDrags[i].thisSkill; SaveInactiveSkillXML(sk.ID, sk.name, sk.Cd, sk.detail, sk.spritePath, sk.MpCost, sk.MpCost, i); } else { SaveInactiveSkillXML(-1, "", 0, "", "", 0, 0, i); //无技能 } } } inactiveSkillXml.Save(path + "/SkillsInavtive.xml");//保存为启用的技能信息 skillload.positionIdxs = skills_OnUI_Pos; skillload.skillsonUI = skills_OnUI; }
public void TestOASIS () { XmlDocument doc = new XmlDocument (); doc.NodeInserting += new XmlNodeChangedEventHandler (OnInserting); doc.NodeInserted += new XmlNodeChangedEventHandler (OnInserted); doc.NodeChanging += new XmlNodeChangedEventHandler (OnChanging); doc.NodeChanged += new XmlNodeChangedEventHandler (OnChanged); doc.NodeRemoving += new XmlNodeChangedEventHandler (OnRemoving); doc.NodeRemoved += new XmlNodeChangedEventHandler (OnRemoved); foreach (FileInfo fi in new DirectoryInfo (@"xml-test-suite/xmlconf/oasis").GetFiles ("*.xml")) { try { if (fi.Name.IndexOf ("fail") >= 0) continue; Console.WriteLine ("#### File: " + fi.Name); XmlTextReader xtr = new XmlTextReader (fi.FullName); xtr.Namespaces = false; xtr.Normalization = true; doc.RemoveAll (); doc.Load (xtr); } catch (XmlException ex) { if (fi.Name.IndexOf ("pass") >= 0) Console.WriteLine ("Incorrectly invalid: " + fi.FullName + "\n" + ex.Message); } } }
public static void Ignore(string path, string xpath, Dictionary <string, string> nameSpaces) { XmlDocument xmlDocument = new XmlDocument(); XmlNamespaceManager ns = new XmlNamespaceManager(xmlDocument.NameTable); if (nameSpaces != null) { foreach (string key in nameSpaces.Keys) { ns.AddNamespace(key, nameSpaces[key]); } } xmlDocument.Load(path); XmlNodeList xmlNodes = xmlDocument.SelectNodes(xpath, ns); if (xmlNodes != null) { foreach (XmlNode xmlNode in xmlNodes) { xmlNode.InnerText = "Ignore"; } if (xmlNodes.Count > 0) { xmlDocument.Save(path); } } xmlDocument.RemoveAll(); }
/// <summary> /// Method to log error message to xml file /// </summary> /// <author>Sudha Gubbala</author> /// <CreatedDate>6/18/2012</CreatedDate> /// <param name="ex"></param> public static void WriteError(Exception ex) { try { var doc = new XmlDocument(); var xmlPath = HttpContext.Current.Server.MapPath("Errorlog.xml"); doc.Load(@xmlPath); var oldXmlNode = doc.ChildNodes[1].ChildNodes[0]; var newXmlNode = oldXmlNode.CloneNode(true); var stackTrace = new StackTrace(); var stackFrame = stackTrace.GetFrame(1); var methodBase = stackFrame.GetMethod(); newXmlNode.ChildNodes[0].InnerText = DateTime.Now.ToString(); newXmlNode.ChildNodes[1].InnerText = GetCurrentPageName(); newXmlNode.ChildNodes[2].InnerText = methodBase.DeclaringType.FullName; newXmlNode.ChildNodes[3].InnerText = methodBase.Name; newXmlNode.ChildNodes[4].InnerText = ex.TargetSite.Name; newXmlNode.ChildNodes[5].InnerText = ex.Message; newXmlNode.ChildNodes[6].InnerText = ex.StackTrace; newXmlNode.ChildNodes[7].InnerText = HttpContext.Current.Request.UserHostAddress; newXmlNode.ChildNodes[8].InnerText = HttpContext.Current.Request.Url.OriginalString; doc.ChildNodes[1].AppendChild(newXmlNode); if ((File.GetAttributes(@xmlPath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(@xmlPath, FileAttributes.Normal); } doc.Save(@xmlPath); doc.RemoveAll(); } catch { } }
/// <summary> /// 构造函数 /// </summary> private CysoftCache() { //TODO:YZQ 临时禁用 //if (MemCachedConfigs.GetConfig() != null && MemCachedConfigs.GetConfig().ApplyMemCached) // applyMemCached = true; //if (RedisConfigs.GetConfig() != null && RedisConfigs.GetConfig().ApplyRedis) // applyRedis = true; if (applyMemCached || applyRedis) { try { string typeName = string.Format("Cysoft.CacheStrategy.{0}, Cysoft.CacheStrategy", (applyMemCached ? "MemCached" : "Redis")); cs = cachedStrategy = (ICacheStrategy)Activator.CreateInstance(Type.GetType(typeName: typeName, throwOnError: false, ignoreCase: true)); } catch { throw new Exception("请检查Cysoft.CacheStrategy.dll文件是否被放置在bin目录下并配置正确"); } } else { cs = new DefaultCacheStrategy(); if (rootXml.HasChildNodes) { rootXml.RemoveAll(); } objectXmlMap = rootXml.CreateElement("Cache"); //建立内部XML文档. rootXml.AppendChild(objectXmlMap); } }