/// <summary> /// Select a list of nodes based on an XPath style string which match a particular type /// </summary> /// <example> /// <code lang="cs"> /// Select all nodes in the tree with the name value /// DataNode[] nodes = node.SelectNodes("//value"); /// </code> /// </example> /// <param name="path">The XPath selector</param> /// <returns>A list of nodes select</returns> public T[] SelectNodes <T>(string path) where T : DataNode { List <T> nodes = new List <T>(); try { XPathDataNavigator xpath = new XPathDataNavigator(this, false); XPathNodeIterator it = xpath.Select(path.ToLower()); while (it.MoveNext()) { T value = it.Current.UnderlyingObject as T; if (value != null) { nodes.Add(value); } } } catch (XPathException ex) { Logger.GetSystemLogger().LogException(ex); } return(nodes.ToArray()); }
public override bool MoveTo(XPathNavigator other) { if (other is XPathDataNavigator) { XPathDataNavigator nav = other as XPathDataNavigator; _currNode = nav._currNode; return(true); } return(false); }
public override bool IsSamePosition(XPathNavigator other) { if (other is XPathDataNavigator) { XPathDataNavigator x = other as XPathDataNavigator; if (x._currNode == _currNode) { return(true); } } return(false); }
/// <summary> /// Select the first node which matches an XPath style path and is of the required type /// </summary> /// <param name="path">The XPath selector</param> /// <typeparam name="T">The type of node to return</typeparam> /// <returns>The first node, or null if none found</returns> public T SelectSingleNode <T>(string path) where T : DataNode { try { XPathDataNavigator xpath = new XPathDataNavigator(this, false); XPathNodeIterator it = xpath.Select(path.ToLower()); if (it.MoveNext()) { T value = it.Current.UnderlyingObject as T; if (value != null) { return(value); } } } catch (XPathException ex) { Logger.GetSystemLogger().LogException(ex); } return(null); }