/// <summary> /// 插入或创建指定节点路径上的节点 /// </summary> /// <param name="NodePath">以点分的方式指出节点全路径</param> /// <returns></returns> public XmlNode InsertXmlNode(string NodePath) { ArrayList NodeList = new GetPageCode().GetItemsUseRegex(@"[A-Za-z0-9]+", NodePath); XmlNode TemNode1; XmlNode TemNode2 = (XmlNode)_XmlDocument; if (NodeList != null) { for (int i = 0; i < NodeList.Count; i++) { TemNode1 = TemNode2.SelectSingleNode(NodeList[i].ToString()); if (TemNode1 != null) { TemNode2 = TemNode1; TemNode1 = null; } else { TemNode1 = _XmlDocument.CreateElement(NodeList[i].ToString()); TemNode2.AppendChild(TemNode1); TemNode2 = TemNode2.SelectSingleNode(NodeList[i].ToString()); TemNode1 = null; } } } return(TemNode2); }
/// <summary> /// 选中指定节点路径的节点 /// </summary> /// <param name="NodePath"></param> /// <returns></returns> public XmlNode SelectNode(string NodePath) { ArrayList NodeList = new GetPageCode().GetItemsUseRegex(@"[A-Za-z0-9]+", NodePath); XmlNode TemNode1; XmlNode TemNode2 = (XmlNode)_XmlDocument; if (NodeList != null) { for (int i = 0; i < NodeList.Count; i++) { TemNode1 = TemNode2.SelectSingleNode(NodeList[i].ToString()); if (TemNode1 != null) { TemNode2 = TemNode1; TemNode1 = null; } else { throw new Exception("指定的节点(" + NodeList[i].ToString() + ")不存在,请确认你的节点路径是否正确。"); } } } return(TemNode2); }