/// <summary> /// Initializes the reader. /// </summary> /// <param name="iterator">The iterator to expose as a single reader.</param> /// <param name="rootName">The name to use for the enclosing root element.</param> /// <param name="ns">The namespace URI of the root element.</param> public XPathIteratorReader(XPathNodeIterator iterator, string rootName, string ns) : base(new StringReader(String.Empty)) { _iterator = iterator.Clone(); _current = new FakedRootReader(rootName, ns, XmlNodeType.Element); _rootname = new XmlQualifiedName(rootName, ns); }
protected static XPathNodeIterator Clone(XPathNodeIterator input) { if (input != null) { return input.Clone(); } return null; }
public XmlIteratorNodeList (XmlDocument doc, XPathNodeIterator iter) { if (doc == null) throw new Exception ("huh?"); this.doc = doc; //doc.NodeRemoving += SaveNodeList; source = iter; iterator = iter.Clone (); list = new ArrayList (); }
// Create a new node list. public SelectNodeList(XPathNodeIterator iterator) { if(iterator != null) { this.iterator = iterator.Clone(); this.current = iterator.Clone(); finished = false; } else { finished = true; } cached = new ArrayList(); }
/// <summary> /// Initializes the ExsltNodeList with the specified XPathNodeIterator. All nodes /// in the iterator are placed in the list. /// </summary> /// <param name="iterator">The iterator to load the nodelist from</param> /// <param name="removeDuplicates">A flag that indicates whether duplicate nodes /// should be loaded into the nodelist or only node with unique identity should /// be added</param> public ExsltNodeList(XPathNodeIterator iterator, bool removeDuplicates){ XPathNodeIterator it = iterator.Clone(); while(it.MoveNext()){ if(removeDuplicates){ if(this.Contains(it.Current)){ continue; } } this.Add(it.Current.Clone()); } }
public virtual bool MoveNext() { // Delegate to XPathNodeIterator if (!_iterationStarted) { // Reset iteration to original position _current = _original.Clone(); _iterationStarted = true; } if (_current == null || !_current.MoveNext()) { // Iteration complete _current = null; return(false); } return(true); }
/// <summary> /// Selects nodes from the specified <paramref name="nodeset"/> that have unique values selected with <paramref name="xpath"/>. /// </summary> /// <param name="nodeset">The <c>nodeset</c> that contains the nodes to filter.</param> /// <param name="xpath">The xpath to use to select the value that should be unique between nodes.</param> /// <param name="includeNullEntries">If set to <c>true</c>, nodes that fail to select the specified <paramref name="xpath"/> will be included too.</param> /// <returns> /// The nodes from the specified <paramref name="nodeset"/> that have unique values selected with <paramref name="xpath"/>. /// </returns> public XPathNodeIterator distinct(XPathNodeIterator nodeset, string xpath, bool includeNullEntries) { if (nodeset.Count < 2) return nodeset; var result = new List<NodeInfo>(); var selections = new List<string>(); XPathNodeIterator clone = nodeset.Clone(); while (clone.MoveNext()) { XPathNavigator selected = clone.Current.SelectSingleNode(xpath); if (selected == null) { if (includeNullEntries) result.Add(new NodeInfo(clone.Current)); continue; } if (!selections.Contains(selected.Value)) { selections.Add(selected.Value); result.Add(new NodeInfo(clone.Current)); } } if (result.Count > 0) { List<string> distinct = result.Select(t => t.XPath).ToList(); return result[0].Root.Select(string.Join(" | ", distinct), NodeInfo.GetNamespaceManager(result)); } return empty.Select("*"); }
/// <summary> /// Returns <paramref name="nodeset1"/> if it is not empty, otherwise <paramref name="nodeset2"/>. /// </summary> /// <param name="nodeset1">The primary selection.</param> /// <param name="nodeset2">The secondary selection.</param> /// <returns><paramref name="nodeset1"/> if it is not empty, otherwise <paramref name="nodeset2"/></returns> public XPathNodeIterator either(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2) { return nodeset1.Count != 0 ? nodeset1.Clone() : nodeset2.Clone(); }
private XPathNodeIterator original; // Keep original XPathNodeIterator in case Reset() is called #endregion Fields #region Constructors public Enumerator(XPathNodeIterator original) { this.original = original.Clone(); }
public Enumerator(XPathNodeIterator original) { _original = original.Clone(); }
public XmlNodeListIterator(XPathNodeIterator iterator) { _iterator = iterator.Clone(); }
/// <summary> /// InsureFontNameAttributes /// </summary> /// <param name="xpIterator"></param> /// <param name="xpe"></param> /// <param name="strNewFontName"></param> /// <param name="bCreateIfNotPresent">indicates whether to create the attribute/element if it doesn't already exist</param> /// <returns>true if the attribute was already present; false if not (whether it was created or not)</returns> protected bool InsureFontNameAttributes(XPathNodeIterator xpIterator, XPathExpression xpe, string strNewFontName, bool bCreateIfNotPresent) { XPathNodeIterator xpIteratorAttrib = xpIterator.Current.Select(xpe); if (xpIteratorAttrib.MoveNext()) { xpIteratorAttrib.Current.SetValue(strNewFontName); return true; } else if (bCreateIfNotPresent) { xpIteratorAttrib = xpIterator.Clone(); string strExpr = xpe.Expression; // this code only handles expressions of the form "w:x/y:z" so there should be 4 "parts") string[] astrSplit = strExpr.Split(new char[] { '/', ':', '@' }, StringSplitOptions.RemoveEmptyEntries); System.Diagnostics.Debug.Assert(astrSplit.Length == 6); string strChildElementPrefix = astrSplit[0]; string strNameSpace = m_mapPrefix2NamespaceURI[strChildElementPrefix]; string strChildElementName = astrSplit[1]; int nOffset = 0; if (astrSplit.Length == 6) { if (!xpIteratorAttrib.Current.MoveToChild(strChildElementName, strNameSpace)) { xpIteratorAttrib.Current.PrependChildElement(strChildElementPrefix, strChildElementName, strNameSpace, null); bool bMoveRes = xpIteratorAttrib.Current.MoveToChild(strChildElementName, strNameSpace); System.Diagnostics.Debug.Assert(bMoveRes); } nOffset = 2; } strChildElementPrefix = astrSplit[0 + nOffset]; strNameSpace = m_mapPrefix2NamespaceURI[strChildElementPrefix]; strChildElementName = astrSplit[1 + nOffset]; string strAttribPrefix = astrSplit[2 + nOffset]; string strAttribName = astrSplit[3 + nOffset]; if (!xpIteratorAttrib.Current.MoveToChild(strChildElementName, strNameSpace)) { xpIteratorAttrib.Current.PrependChildElement(strChildElementPrefix, strChildElementName, strNameSpace, null); bool bMoveRes = xpIteratorAttrib.Current.MoveToChild(strChildElementName, strNameSpace); System.Diagnostics.Debug.Assert(bMoveRes); } xpIteratorAttrib.Current.CreateAttribute(strAttribPrefix, strAttribName, strNameSpace, strNewFontName); } return false; }
public XPathNodeIteratorEnumerator(XPathNodeIterator source) { this.source = source.Clone(); current = null; }
internal void Init(XPathNodeIterator i, string query = "/") { _i = i.Clone(); if (_i.CurrentPosition == 0) // standing before first node _i.MoveNext(); _nav = _i.Current; base_xml = _nav.OuterXml; _query = query; #if DEBUG Debug.Print("xml:\n" + base_xml + "\n"); Debug.Print("query:" + _query + "\n\n"); #endif }
public XmlIteratorNodeList (XPathNodeIterator iter) { source = iter; iterator = iter.Clone (); list = new ArrayList (); }
public XPathNodeIterator rel_join(XPathNodeIterator one, XPathNodeIterator two, string by, string name, string prefix, string ns, string fp, string sp){ var sw = new StringWriter(); XmlWriter w = new XmlTextWriter(sw); w.WriteStartElement("root"); w.WriteAttributeString("xmlns", "xes", "http://www.w3.org/2000/xmlns/", "MT-xml-expert-systems"); while (one.MoveNext()){ var t = two.Clone(); while (t.MoveNext()){ w.WriteStartElement(prefix, name, ns); var attrs = one.Current.Clone(); while (attrs.MoveToFirstAttribute() || attrs.MoveToNextAttribute()){ if (attrs.Prefix == "xes" && attrs.LocalName == "UID") continue; w.WriteAttributeString(attrs.Prefix, fp + attrs.LocalName, attrs.NamespaceURI, attrs.Value); } attrs = t.Current.Clone(); while (attrs.MoveToFirstAttribute() || attrs.MoveToNextAttribute()){ if (attrs.Prefix == "xes" && attrs.LocalName == "UID") continue; w.WriteAttributeString(attrs.Prefix, sp + attrs.LocalName, attrs.NamespaceURI, attrs.Value); } w.WriteEndElement(); } } w.WriteEndElement(); w.Flush(); var nav = XmlUtil.GetNavigator(sw.ToString()); var res = nav.Select("/root/*[" + by + "]"); return res; }
public XPathNodeIteratorEnumerator (XPathNodeIterator source) { this.source = source.Clone (); current = null; }
/// <summary> /// A helper method to retrieve the right Item. If the current item is a variant and /// a specific field doesn't exist on the variant, then the parent item is returned. /// </summary> /// <param name="fieldName"> /// </param> /// <param name="ni"> /// </param> public XPathNodeIterator selectProduct(string fieldName, XPathNodeIterator ni) { XPathNodeIterator clone = ni.Clone(); var helper = new Xml.Xsl.XslHelper(); string fldValue = helper.fld(fieldName, clone); if (fldValue.Length > 0) { return ni; } string currentId = clone.Current.GetAttribute("id", string.Empty); Item currentItem = Sitecore.Context.Database.GetItem(currentId); if (currentItem != null) { Item parentItem = currentItem.Parent; if (parentItem != null && parentItem.Fields[fieldName] != null) { return helper.item(parentItem.Paths.FullPath, ni); } } return ni; }