/// <summary> /// <p> /// This returns a <code>NodeList</code> of all the child elements /// nested directly (one level deep) within this element, as /// <code>Element</code> objects. If this target element has no nested /// elements, an empty List is returned. The returned list is "live" /// in document order and changes to it affect the element's actual /// contents. /// </p> /// <p> /// This performs no recursion, so elements nested two levels /// deep would have to be obtained with: /// <pre> /// <code> /// Iterator itr = currentElement.getChildren().iterator(); /// while (itr.hasNext()) { /// Element oneLevelDeep = (Element)nestedElements.next(); /// List twoLevelsDeep = oneLevelDeep.getChildren(); /// // Do something with these children /// } /// </code> /// </pre> /// </p> /// </summary> /// <returns>list of child <code>Element</code> objects for this element</returns> public virtual IList GetChildren() { XmlNodeList xnl = base.ChildNodes; NodeList nl = new NodeList(); foreach(Object o in xnl) { if(o is AnakiaXmlElement) { nl.Add(o); } } return nl; }
/// <summary> /// Applies an XPath expression to the node list and returns the resulting /// node list. In order for this method to work, your application must have /// access to <a href="http://code.werken.com">werken.xpath</a> library /// classes. The implementation does cache the parsed format of XPath /// expressions in a weak hash map, keyed by the string representation of /// the XPath expression. As the string object passed as the argument is /// usually kept in the parsed template, this ensures that each XPath /// expression is parsed only once during the lifetime of the template that /// first invoked it. /// </summary> /// <param name="xpathExpression">the XPath expression you wish to apply</param> /// <returns>a NodeList representing the nodes that are the result of /// application of the XPath to the current node list. It can be empty. /// </returns> public virtual NodeList selectNodes(System.String xpathString) { NodeList nl = new NodeList(); foreach(XmlNode node in nodes) { XPathNavigator nav = node.CreateNavigator(); if (nav.Matches(xpathString)) { nl.Add(node); } } return nl; }
/// <summary> /// <p> /// This returns a <code>NodeList</code> of all the child elements /// nested directly (one level deep) within this element with the given /// local name and belonging to the given Namespace, returned as /// <code>Element</code> objects. If this target element has no nested /// elements with the given name in the given Namespace, an empty List /// is returned. The returned list is "live" in document order /// and changes to it affect the element's actual contents. /// </p> /// <p> /// Please see the notes for <code>{@link #getChildren}</code> /// for a code example. /// </p> /// </summary> /// <param name="name">local name for the children to match</param> /// <param name="ns"><code>Namespace</code> to search within</param> /// <returns>all matching child elements</returns> public virtual IList GetChildren(System.String name, String ns) { XmlNodeList xnl = base.ChildNodes; NodeList nl = new NodeList(); foreach(Object o in xnl) { if(o is AnakiaXmlElement) { AnakiaXmlElement element = (AnakiaXmlElement)o; if (element.LocalName.Equals(name) && element.NamespaceURI.Equals(ns)) { nl.Add(o); } } } return nl; }