using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace Sinvo.EplanHpD.Plugin.DynaClient { public class XMLMethod { /// /// XML的SelectSingleNode的替代方法 /// /// /// /// public static XmlNode GetXmlNode(XmlDocument xmlDoc, string nodeFullName) { if (xmlDoc.ChildNodes.Count > 0) { int index = nodeFullName.IndexOf("/"); string nodeName = null; if (index > -1) { nodeName = nodeFullName.Substring(0, index); } else { nodeName = nodeFullName; } foreach (XmlNode tempNode in xmlDoc.ChildNodes) { if (string.Compare(tempNode.Name, nodeName, true) == 0) { if (index > -1) { int fullNameLength = nodeFullName.Length - index - 1; if (fullNameLength < 1) { return tempNode; } else { string childNodeFullName = nodeFullName.Substring(index + 1, fullNameLength); return GetChildNode(tempNode, childNodeFullName); } } else { return tempNode; } } } } return null; } private static XmlNode GetChildNode(XmlNode node, string nodeFullName) { int index = nodeFullName.IndexOf("/"); string nodeName = null; if (index > -1) { nodeName = nodeFullName.Substring(0, index); } else { nodeName = nodeFullName; } foreach (XmlNode tempNode in node.ChildNodes) { if (string.Compare(tempNode.Name, nodeName, true) == 0) { if (index > -1) { int fullNameLength = nodeFullName.Length - index - 1; if (fullNameLength < 1) { return tempNode; } else { string childNodeFullName = nodeFullName.Substring(index + 1, fullNameLength); return GetChildNode(tempNode, childNodeFullName); } } else { return tempNode; } } } return null; } } }