EPLAN_PROD_Plugin/Sinvo.EplanHpD.Plugin.DynaC.../XMLMethod.cs

98 lines
3.1 KiB
C#
Raw Normal View History

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
{
/// <summary>
/// XML的SelectSingleNode的替代方法
/// </summary>
/// <param name="xmlDoc"></param>
/// <param name="nodeFullName"></param>
/// <returns></returns>
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;
}
}
}