public override System.Xml.XmlNode WriteTo(System.Xml.XmlNode parent) { XmlElement startProcessMethodsElement = parent.SelectSingleNode("child::" + name) as XmlElement; if (startProcessMethodsElement != null) { parent.RemoveChild(startProcessMethodsElement); } startProcessMethodsElement = parent.OwnerDocument.CreateElement(name); parent.AppendChild(startProcessMethodsElement); if (values != null) { foreach (ProcessMethod method in values) { XmlElement startMethodElement = parent.OwnerDocument.CreateElement("StartMethod"); startMethodElement.InnerText = method.MethodName; startProcessMethodsElement.AppendChild(startMethodElement); XmlAttribute sequenceAttribute = parent.OwnerDocument.CreateAttribute("Sequence"); sequenceAttribute.Value = method.Sequence.ToString(); startMethodElement.Attributes.Append(sequenceAttribute); } } return null; }
public override System.Xml.XmlNode WriteTo(System.Xml.XmlNode parent) { XmlElement endProcessMethodsElement = parent.SelectSingleNode("child::" + name) as XmlElement; if (endProcessMethodsElement != null) { parent.RemoveChild(endProcessMethodsElement); } endProcessMethodsElement = parent.OwnerDocument.CreateElement(name); parent.AppendChild(endProcessMethodsElement); if (values != null) { foreach (ThresholdYield ty in values) { XmlElement thresholdYieldElement = parent.OwnerDocument.CreateElement("ThresholdYield"); endProcessMethodsElement.AppendChild(thresholdYieldElement); XmlAttribute yieldAttribute = parent.OwnerDocument.CreateAttribute("Yield"); yieldAttribute.Value = ty.YieldMax.ToString(); thresholdYieldElement.Attributes.Append(yieldAttribute); //Methods for threshold yield XmlElement endMethodElement = thresholdYieldElement.SelectSingleNode("child::EndMethod") as XmlElement; if (endMethodElement != null) { thresholdYieldElement.RemoveChild(endMethodElement); } foreach (ProcessMethod method in ty.Methods) { endMethodElement = thresholdYieldElement.OwnerDocument.CreateElement("EndMethod"); endMethodElement.InnerText = method.MethodName; thresholdYieldElement.AppendChild(endMethodElement); XmlAttribute sequenceAttribute = thresholdYieldElement.OwnerDocument.CreateAttribute("Sequence"); sequenceAttribute.Value = method.Sequence.ToString(); endMethodElement.Attributes.Append(sequenceAttribute); } } } return null; }
/// <summary>Removes attributes, comments, and processing instructions. </summary> private static void clean(System.Xml.XmlElement elem) { System.Xml.XmlNodeList children = elem.ChildNodes; for (int i = 0; i < children.Count; i++) { System.Xml.XmlNode child = children.Item(i); if (System.Convert.ToInt16(child.NodeType) == (short) System.Xml.XmlNodeType.ProcessingInstruction || System.Convert.ToInt16(child.NodeType) == (short) System.Xml.XmlNodeType.Comment) { elem.RemoveChild(child); } else if (System.Convert.ToInt16(child.NodeType) == (short) System.Xml.XmlNodeType.Element) { clean((System.Xml.XmlElement) child); } } System.Xml.XmlNamedNodeMap attributes = (System.Xml.XmlAttributeCollection) elem.Attributes; //get names System.String[] names = new System.String[attributes.Count]; for (int i = 0; i < names.Length; i++) { names[i] = attributes.Item(i).Name; } //remove by name for (int i = 0; i < names.Length; i++) { attributes.RemoveNamedItem(names[i]); } }
private void RemoveUnsupportedNodes(System.Xml.XmlNode xmlNode) { System.Xml.XmlNode firstChild = xmlNode.FirstChild; while (firstChild != null) { if (firstChild.NodeType == XmlNodeType.Comment) { System.Xml.XmlNode oldChild = firstChild; firstChild = firstChild.NextSibling; xmlNode.RemoveChild(oldChild); } else { this.RemoveUnsupportedNodes(firstChild); firstChild = firstChild.NextSibling; } } }
/// <summary> /// Recursively prune each folder /// </summary> /// <param name="hCurFolder"></param> /// <returns></returns> protected bool PruneFolder(System.Xml.XmlNode hCurFolder) { bool bFoundDataSet = false; for (Int32 i = 0; i < hCurFolder.ChildNodes.Count; i++) { System.Xml.XmlNode hNode = hCurFolder.ChildNodes[i]; if (hNode.Name == Geosoft.Dap.Xml.Common.Constant.Tag.COLLECTION_TAG) { bool bFoundChildDataSet = PruneFolder(hNode); // --- no datasets, down this path --- if (!bFoundChildDataSet) { hCurFolder.RemoveChild(hNode); i--; } else { bFoundDataSet = true; // only need 1 child to have it to keep parent } } else if (hNode.Name == Geosoft.Dap.Xml.Common.Constant.Tag.ITEM_TAG) { bFoundDataSet = true; } } return bFoundDataSet; }
public override System.Xml.XmlNode WriteTo(System.Xml.XmlNode parent) { XmlElement lpEventsElement = parent.SelectSingleNode("child::" + name) as XmlElement; if (lpEventsElement != null) { parent.RemoveChild(lpEventsElement); } lpEventsElement = parent.OwnerDocument.CreateElement(name); parent.AppendChild(lpEventsElement); if (values != null) { foreach (LongPauseEventListData lpEvent in values) { XmlElement nameElement = parent.OwnerDocument.CreateElement("LpEvent"); lpEventsElement.AppendChild(nameElement); XmlAttribute nameAttribute = parent.OwnerDocument.CreateAttribute("Name"); nameAttribute.Value = lpEvent.Name; nameElement.Attributes.Append(nameAttribute); XmlAttribute enambledAttribute = parent.OwnerDocument.CreateAttribute("Enabled"); enambledAttribute.Value = lpEvent.Enabled.ToString(); nameElement.Attributes.Append(enambledAttribute); XmlAttribute reasonCodeAttribute = parent.OwnerDocument.CreateAttribute("ReasonCode"); reasonCodeAttribute.Value = lpEvent.ReasonCode.ToString(); nameElement.Attributes.Append(reasonCodeAttribute); } } return null; }