/// <summary> /// Создаем узел с аттрибутами /// </summary> /// <param name="name"></param> /// <param name="attributes"></param> /// <param name="inner_text"></param> /// <param name="parent_node"></param> public XmlElement CreateElement(string name, Dictionary <string, string> attributes, string inner_text, XmlElement parent_element) { try{ XmlElement node = xml_document.CreateElement(name); // пройдемся по аттрибутам... if (attributes != null) { foreach (KeyValuePair <string, string> param in attributes) { XmlAttribute attrib = null; if (param.Key.IndexOf(":") > 0) { attrib = xml_document.CreateAttribute(param.Key.Substring(0, param.Key.IndexOf(":")), param.Key.Substring(param.Key.IndexOf(":") + 1, param.Key.Length - param.Key.IndexOf(":") - 1)); } else { attrib = xml_document.CreateAttribute(param.Key); } attrib.InnerText = param.Value.ToString(); node.Attributes.Append(attrib); } } node.InnerText = inner_text; parent_element.AppendChild(node); XmlElements.Add(node); return(node); } catch (XmlException ex) { throw new XmlFunException(ex.Message); } }
/// <summary> /// Создаем узел с аттрибутами /// </summary> /// <param name="name"></param> /// <param name="attributes"></param> /// <param name="inner_text"></param> /// <param name="parent_node"></param> public XmlNode CreateNode(string name, Dictionary <string, string> attributes, string inner_text, XmlNode parent_node) { try{ XmlNode node = xml_document.CreateNode(XmlNodeType.Element, name, String.Empty); // пройдемся по аттрибутам... if (attributes != null) { foreach (KeyValuePair <string, string> param in attributes) { XmlAttribute attrib = null; if (param.Key.IndexOf(":") > 0) { attrib = xml_document.CreateAttribute(param.Key, "special_ns"); } else { attrib = xml_document.CreateAttribute(param.Key); } attrib.InnerText = param.Value.ToString(); node.Attributes.Append(attrib); } } node.InnerText = inner_text; parent_node.AppendChild(node); XmlElements.Add((XmlElement)node); return(node); } catch (XmlException ex) { throw new XmlFunException(ex.Message); } }
/// <summary> /// Создаем документ и назначаем ему имя /// </summary> /// <param name="document_name">имя</param> /// <param name="inner_xml">содержимое</param> public void CreateDocument(string document_name, string inner_xml) { CreateDocument(document_name); xml_document.InnerXml = inner_xml; XmlElements.Clear(); FillXmlElements(xml_document); }
/// <summary> /// Загрузка документа /// </summary> /// <param name="filename"></param> public void LoadDocument(string filename) { try { XmlTextReader xmlreader = new XmlTextReader(File.Open(filename, FileMode.Open)); xml_document = new XmlDocument(); xml_document.Load(xmlreader); XmlElements.Clear(); FillXmlElements(xml_document); xmlreader.Close(); } catch (XmlException ex) { throw new XmlFunException(ex.Message); } }
/// <summary> /// Loads instance from XML. /// </summary> /// <param name="itemNode">Node to load XML from</param> /// <returns>true if sucessfully loaded from XML</returns> public void Load(XmlNode fileNode) { // Loop through sub-nodes foreach (XmlNode propNode in fileNode.ChildNodes) { // Get element/property type XmlElements element = XmlElements.FilePath; bool exists = false; foreach (XmlElements el in Enum.GetValues(typeof(XmlElements))) { if (el.ToString() == propNode.Name) { element = el; exists = true; break; } } // If unknown element go to next if (!exists) { continue; } // Get value string string value = propNode.InnerText; // Load value into appropriate property switch (element) { case XmlElements.FilePath: this.FilePath = value; break; case XmlElements.Part: int part; int.TryParse(value, out part); this.Part = part; break; case XmlElements.MultiPart: bool multiPart; bool.TryParse(value, out multiPart); this.MultiPart = multiPart; break; } } }
public void FillXmlElements(ExtXmlNode elem) { Parallel.ForEach(elem.InnerNode.ChildNodes.Cast <XmlNode>(), parallel_options, (el, loop_state) => { ExtXmlNode ext_el = new ExtXmlNode(el); if (ext_el != null) { if (!(ext_el.InnerNode is XmlText) && !(ext_el.InnerNode is XmlDeclaration) && !(ext_el.InnerNode is XmlWhitespace) && !(ext_el.InnerNode is XmlSignificantWhitespace)) { lock (XmlElements) { XmlElements.Add((XmlElement)ext_el.InnerNode); } FillXmlElements(ext_el); } } }); }
public void FillXmlElements(XmlDocument doc) { XmlElements.Clear(); XmlElements.Add(doc.DocumentElement); Parallel.ForEach(doc.DocumentElement.ChildNodes.Cast <XmlNode>(), parallel_options, (el, loop_state) => { if (!(el is XmlDeclaration) && !(el is XmlSignificantWhitespace)) { ExtXmlNode ext_el = new ExtXmlNode(el); if (ext_el != null) { lock ( XmlElements ) { XmlElements.Add((XmlElement)ext_el.InnerNode); } FillXmlElements(ext_el); } } }); XmlElements.Sort(_SortFunc); }
/// <summary> /// Loads instance from XML. /// </summary> /// <param name="itemNode">Node to load XML from</param> /// <returns>true if sucessfully loaded from XML</returns> public bool Load(XmlNode seasonNode) { if (seasonNode.Name != ROOT_XML) { return(false); } foreach (XmlNode propNode in seasonNode.ChildNodes) { XmlElements element = XmlElements.Number; if (!Enum.TryParse <XmlElements>(propNode.Name, out element)) { continue; } string value = propNode.InnerText; switch (element) { case XmlElements.Number: int number; if (int.TryParse(value, out number)) { this.Number = number; } break; case XmlElements.Episodes: this.Episodes = new List <TvEpisode>(); foreach (XmlNode epNode in propNode.ChildNodes) { TvEpisode episode = new TvEpisode(); episode.Load(epNode); Episodes.Add(episode); } Episodes.Sort(); break; } } return(true); }
/// <summary> /// Удаление узла /// </summary> /// <param name="name">Имя узла</param> /// <param name="attributes">Аттрибуты зла</param> public void RemoveNode(string name, Dictionary <string, string> attributes = null) { XmlElement tmp_el = FindFirstNode(name, attributes); tmp_el.RemoveAll(); if (tmp_el != null) { if (tmp_el.ParentNode != null) { tmp_el.ParentNode.RemoveChild(tmp_el); } else { tmp_el.OwnerDocument.RemoveChild(tmp_el); } FillXmlElements(xml_document); XmlElements.Remove(tmp_el); } FillXmlElements(xml_document); }
/// <summary> /// Загрузка документа /// </summary> /// <param name="filename"></param> public void LoadDocument(XmlDocument _xml_document) { xml_document = _xml_document; XmlElements.Clear(); FillXmlElements(xml_document); }
public GetDayTemplateResponse Clone() => new GetDayTemplateResponse(XmlElements.DeepClone(), DocumentPart);