MoveToNext() public abstract method

public abstract MoveToNext ( ) : bool
return bool
Example #1
0
        [Test] //ExSkip
        public void NodeXPathNavigator()
        {
            // Create a blank document
            Document doc = new Document();

            // A document is a composite node so we can make a navigator straight away
            System.Xml.XPath.XPathNavigator navigator = doc.CreateNavigator();

            // Our root is the document node with 1 child, which is the first section
            Assert.AreEqual("Document", navigator.Name);
            Assert.AreEqual(false, navigator.MoveToNext());
            Assert.AreEqual(1, navigator.SelectChildren(XPathNodeType.All).Count);

            // The document tree has the document, first section, body and first paragraph as nodes, with each being an only child of the previous
            // We can add a few more to give the tree some branches for the navigator to traverse
            DocumentBuilder docBuilder = new DocumentBuilder(doc);

            docBuilder.Write("Section 1, Paragraph 1. ");
            docBuilder.InsertParagraph();
            docBuilder.Write("Section 1, Paragraph 2. ");
            doc.AppendChild(new Section(doc));
            docBuilder.MoveToSection(1);
            docBuilder.Write("Section 2, Paragraph 1. ");

            // Use our navigator to print a map of all the nodes in the document to the console
            StringBuilder stringBuilder = new StringBuilder();

            MapDocument(navigator, stringBuilder, 0);
            Console.Write(stringBuilder.ToString());
        }
        private static void Traverse(TextWriter writer, XPathNavigator nav, int depth = 0)
        {
            var leadIn = new string(Constants.Tab, depth);

            if (nav.NodeType == XPathNodeType.Root)
                nav.MoveToFirstChild();

            do
            {
                switch (nav.NodeType)
                {
                    case XPathNodeType.Element:
                        WriteElement(writer, nav, depth, leadIn);
                        break;
                    case XPathNodeType.Text:
                        WriteTextData(writer, nav, leadIn);
                        break;
                    case XPathNodeType.Comment:
                        WriteComment(writer, nav, leadIn);
                        break;
                    default:
                        throw new InvalidDataException("Encountered unsupported node type of " + nav.NodeType);
                }
            } while (nav.MoveToNext());
        }
Example #3
0
 public static string GetStringXML(XPathNavigator xPathNavigator)
 {
     if (xPathNavigator.MoveToNext ())
     {
         return xPathNavigator.Value;
     }
     return null;
 }
 internal static bool MoveToAddressingHeaderSibling(XPathNavigator nav, string name)
 {
     while (nav.MoveToNext())
     {
         if ((nav.LocalName == name) && ((nav.NamespaceURI == "http://www.w3.org/2005/08/addressing") || (nav.NamespaceURI == "http://schemas.xmlsoap.org/ws/2004/08/addressing")))
         {
             return true;
         }
     }
     return false;
 }
Example #5
0
        public static IEnumerable<XPathNavigator> EnumerateChildren(XPathNavigator navigator)
        {
            if (navigator.MoveToFirstChild())
            {
                do
                {
                    yield return navigator;
                } while (navigator.MoveToNext());

                navigator.MoveToParent();
            }
        }
Example #6
0
      public void ReadXml(XPathNavigator node) {

         if (node.MoveToFirstAttribute()) {

            do {
               if (String.IsNullOrEmpty(node.NamespaceURI)) {

                  switch (node.LocalName) {
                     case "method":
                        switch (node.Value) {
                           case "xml":
                              this.Method = XmlSerializationOptions.Methods.Xml;
                              break;

                           case "html":
                              this.Method = XmlSerializationOptions.Methods.Html;
                              break;

                           case "xhtml":
                              this.Method = XmlSerializationOptions.Methods.XHtml;
                              break;

                           case "text":
                              this.Method = XmlSerializationOptions.Methods.Text;
                              break;
                        }
                        break;

                     default:
                        break;
                  }
               }
            } while (node.MoveToNextAttribute());

            node.MoveToParent();
         }

         if (node.MoveToFirstChild()) {

            do {
               if (node.NodeType == XPathNodeType.Element || node.NodeType == XPathNodeType.Text) {
                  this.Content = node.Clone();
                  break;
               }

            } while (node.MoveToNext());

            node.MoveToParent();
         }
      }
        /// <summary>
        /// Updates all of the <c>Torrent</c> object's properties.
        /// </summary>
        /// <param name="node">Torrent XML node</param>
        public void update(XPathNavigator node)
        {
            node.MoveToFirstChild();
            hash = node.Value;
            node.MoveToNext();
            status = Convert.ToInt64(node.Value);
            node.MoveToNext();
            name = node.Value;
            node.MoveToNext();
            size = Convert.ToInt64(node.Value);
            node.MoveToNext();
            percent_progress = Convert.ToInt64(node.Value);

            // skip a tonne of properties
            for (int i = 0; i < 17; i++) node.MoveToNext();
            status_message = node.Value;

            calculateStatus();
            last_modified = DateTime.Now;

            // be kind, rewind
            node.MoveToParent();
        }
Example #8
0
        //creates a dictionary of values found in XML
        private static Dictionary<string, string> ResourceDataToDictionary(XPathNavigator xPathNavigator)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();

            if (xPathNavigator.MoveToFirstChild()) //children
            {
                dict.Add(xPathNavigator.Name, xPathNavigator.Value);
                while (xPathNavigator.MoveToNext())
                {
                    dict.Add(xPathNavigator.Name, xPathNavigator.Value);
                }
            }
            xPathNavigator.MoveToParent();

            return dict;
        }
        /// <summary>
        /// Walks the XPathNavigator tree recursively
        /// </summary>
        /// <param name="myXPathNavigator"></param>
        public static void DisplayTree(XPathNavigator myXPathNavigator)
        {
            if (myXPathNavigator.HasChildren)
            {
                myXPathNavigator.MoveToFirstChild();

                Format(myXPathNavigator);
                DisplayTree(myXPathNavigator);

                myXPathNavigator.MoveToParent();
            }
            while (myXPathNavigator.MoveToNext())
            {
                Format(myXPathNavigator);
                DisplayTree(myXPathNavigator);
            }
        }
 internal static bool MoveToAddressingHeader(XPathNavigator nav, string name)
 {
     if (MoveToHeader(nav))
     {
         if (!nav.MoveToFirstChild())
         {
             return false;
         }
         do
         {
             if ((nav.LocalName == name) && (((nav.NamespaceURI == "http://www.w3.org/2005/08/addressing") || (nav.NamespaceURI == "http://schemas.xmlsoap.org/ws/2004/08/addressing")) || (nav.NamespaceURI == "http://schemas.microsoft.com/ws/2005/05/addressing/none")))
             {
                 return true;
             }
         }
         while (nav.MoveToNext());
     }
     return false;
 }
Example #11
0
        /// <summary>
        /// WebDav Property.
        /// </summary>
        /// <param name="property"></param>
        public DavProperty(XPathNavigator property)
        {
            if (property == null)
                throw new ArgumentNullException("property", InternalFunctions.GetResourceString("ArgumentNullException", "Property"));
            else if (property.NodeType != XPathNodeType.Element)
                throw new ArgumentException(InternalFunctions.GetResourceString("XPathNavigatorElementArgumentException", "Property"), "property");

            base.Name = property.LocalName;
            base.Namespace = property.NamespaceURI;

            if (property.HasAttributes)
            {
                //TODO: Support element attributes
                //string _here = "";
                //Add the attributes first
                //			foreach (XmlAttribute _xmlAttribute in property.Attributes)
                //				Attributes.Add(new DavPropertyAttribute(_xmlAttribute));
            }

            if (property.MoveToFirstChild())
            {
                if (property.NodeType == XPathNodeType.Element)
                {
                    NestedProperties.Add(new DavProperty(property.Clone()));

                    while (property.MoveToNext())
                    {
                        if (property.NodeType == XPathNodeType.Element)
                            NestedProperties.Add(new DavProperty(property.Clone()));
                    }
                }
                else if (property.NodeType == XPathNodeType.Text)
                {
                    base.Value = property.Value;
                    property.MoveToParent();
                }
            }
        }
Example #12
0
        public CreateLine(System.Xml.XPath.XPathNavigator navigator, GEMSSingle parent)
            : base(navigator, parent)
        {
            navigator.MoveToChild("Positions", string.Empty);
            navigator.MoveToFirstChild();

            //Start Point of line
            startPoint   = new Vector3WithUnit();
            startPoint.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty));
            startPoint.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty));
            startPoint.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty));


            //End Point of line
            navigator.MoveToNext();
            endPoint   = new Vector3WithUnit();
            endPoint.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty));
            endPoint.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty));
            endPoint.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty));

            navigator.MoveToParent();
            navigator.MoveToParent();
        }
Example #13
0
        public void RecursiveWalkThroughXpath(XPathNavigator navigator)
        {
            switch (navigator.NodeType)
            {
                case XPathNodeType.Root:
                    //TODO: do this better ie parse xml or html decelration
                    if (IncludeDocType)
                    {
                        textWriter.Write("!!!");
                        textWriter.Write(Environment.NewLine);
                    }
                    break;
                case XPathNodeType.Element:
                    ProcessElement(navigator);
                    break;
                case XPathNodeType.Text:
                    ProcessText(navigator);

                    break;
            }

            if (navigator.MoveToFirstChild())
            {
                do
                {
                    RecursiveWalkThroughXpath(navigator);
                } while (navigator.MoveToNext());

                navigator.MoveToParent();
                CheckUnIndent(navigator);
            }
            else
            {
                CheckUnIndent(navigator);
            }
        }
Example #14
0
        public virtual XmlWriter InsertAfter()
        {
            switch (NodeType)
            {
            case XPathNodeType.Root:
            case XPathNodeType.Attribute:
            case XPathNodeType.Namespace:
                throw new InvalidOperationException(String.Format("Insertion after {0} is not allowed.", NodeType));
            }
            XPathNavigator nav = Clone();

            if (nav.MoveToNext())
            {
                return(nav.InsertBefore());
            }
            else if (nav.MoveToParent())
            {
                return(nav.AppendChild());
            }
            else
            {
                throw new InvalidOperationException("Could not move to parent to insert sibling node");
            }
        }
		private void XmlElementWithAttributes (XPathNavigator nav)
		{
			nav.MoveToFirstChild ();
			AssertNavigator ("#1", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true);
			Assert.IsTrue (!nav.MoveToNext ());
			Assert.IsTrue (!nav.MoveToPrevious ());

			Assert.IsTrue (nav.MoveToFirstAttribute ());
			AssertNavigator ("#2", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false);
			Assert.IsTrue (!nav.MoveToFirstAttribute ());	// On attributes, it fails.

			Assert.IsTrue (nav.MoveToNextAttribute ());
			AssertNavigator ("#3", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false);
			Assert.IsTrue (!nav.MoveToNextAttribute ());

			Assert.IsTrue (nav.MoveToParent ());
			AssertNavigator ("#4", nav, XPathNodeType.Element, "", "img", "", "img", "", true, false, true);

			Assert.IsTrue (nav.MoveToAttribute ("alt", ""));
			AssertNavigator ("#5", nav, XPathNodeType.Attribute, "", "alt", "", "alt", "image Fooooooo!", false, false, false);
			Assert.IsTrue (!nav.MoveToAttribute ("src", ""));	// On attributes, it fails.
			Assert.IsTrue (nav.MoveToParent ());
			Assert.IsTrue (nav.MoveToAttribute ("src", ""));
			AssertNavigator ("#6", nav, XPathNodeType.Attribute, "", "src", "", "src", "foo.png", false, false, false);

			nav.MoveToRoot ();
			AssertNavigator ("#7", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
		}
		private void XmlTwoElementsContent (XPathNavigator nav)
		{
			AssertNavigator ("#1", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);

			Assert.IsTrue (nav.MoveToFirstChild ());
			AssertNavigator ("#2", nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, true, false);
			Assert.IsTrue (!nav.MoveToNext ());
			Assert.IsTrue (!nav.MoveToPrevious ());

			Assert.IsTrue (nav.MoveToFirstChild ());
			AssertNavigator ("#3", nav, XPathNodeType.Element, "", "bar", "", "bar", "", false, false, true);
			Assert.IsTrue (!nav.MoveToFirstChild ());

			Assert.IsTrue (nav.MoveToNext ());
			AssertNavigator ("#4", nav, XPathNodeType.Element, "", "baz", "", "baz", "", false, false, true);
			Assert.IsTrue (!nav.MoveToFirstChild ());

			Assert.IsTrue (nav.MoveToPrevious ());
			AssertNavigator ("#5", nav, XPathNodeType.Element, "", "bar", "", "bar", "", false, false, true);

			nav.MoveToRoot ();
			AssertNavigator ("#6", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
			Assert.IsTrue (!nav.MoveToNext ());
		}
		private void XmlRootElementOnly (XPathNavigator nav)
		{
			AssertNavigator ("#1", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
			Assert.IsTrue (nav.MoveToFirstChild ());
			AssertNavigator ("#2", nav, XPathNodeType.Element, "", "foo", "", "foo", "", false, false, true);
			Assert.IsTrue (!nav.MoveToFirstChild ());
			Assert.IsTrue (!nav.MoveToNext ());
			Assert.IsTrue (!nav.MoveToPrevious ());
			nav.MoveToRoot ();
			AssertNavigator ("#3", nav, XPathNodeType.Root, "", "", "", "", "", false, true, false);
			Assert.IsTrue (!nav.MoveToNext ());
		}
Example #18
0
        protected XPathNavigator MatchNode(XPathNavigator current, IQuery query)
        {
            XPathNavigator context;

            if (current != null)
            {
                context = query.MatchNode(current);
                if (context != null)
                {
                    if (_opnd.ReturnType() == XPathResultType.Number)
                    {
                        if (_opnd.getName() == Querytype.Constant)
                        {
                            XPathNavigator result = current.Clone();

                            int i = 0;
                            if (query.getName() == Querytype.Child)
                            {
                                result.MoveToParent();
                                result.MoveToFirstChild();
                                while (true)
                                {
                                    if (((ChildrenQuery)query).matches(result))
                                    {
                                        i++;
                                        if (current.IsSamePosition(result))
                                        {
                                            if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i)
                                            {
                                                return(context);
                                            }
                                            else
                                            {
                                                return(null);
                                            }
                                        }
                                    }
                                    if (!result.MoveToNext())
                                    {
                                        return(null);
                                    }
                                }
                            }
                            if (query.getName() == Querytype.Attribute)
                            {
                                result.MoveToParent();
                                result.MoveToFirstAttribute();
                                while (true)
                                {
                                    if (((AttributeQuery)query).matches(result))
                                    {
                                        i++;
                                    }
                                    if (current.IsSamePosition(result))
                                    {
                                        if (XmlConvert.ToXPathDouble(_opnd.getValue(current, null)) == i)
                                        {
                                            return(context);
                                        }
                                        else
                                        {
                                            return(null);
                                        }
                                    }
                                    if (!result.MoveToNextAttribute())
                                    {
                                        return(null);
                                    }
                                }
                            }
                        }
                        else
                        {
                            setContext(context.Clone());
                            XPathNavigator result = advance();
                            while (result != null)
                            {
                                if (result.IsSamePosition(current))
                                {
                                    return(context);
                                }
                                result = advance();
                            }
                        }
                    }
                    if (_opnd.ReturnType() == XPathResultType.NodeSet)
                    {
                        _opnd.setContext(current);
                        if (_opnd.advance() != null)
                        {
                            return(context);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    if (_opnd.ReturnType() == XPathResultType.Boolean)
                    {
                        if (noPosition)
                        {
                            if ((bool)_opnd.getValue(current, null))
                            {
                                return(context);
                            }
                            return(null);
                        }
                        setContext(context.Clone());
                        XPathNavigator result = advance();
                        while (result != null)
                        {
                            if (result.IsSamePosition(current))
                            {
                                return(context);
                            }
                            result = advance();
                        }
                        return(null);
                    }
                    if (_opnd.ReturnType() == XPathResultType.String)
                    {
                        if (_opnd.getValue(context, null).ToString().Length > 0)
                        {
                            return(context);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
        public static void WriteNode(this XmlWriter writer, XPathNavigator navigator, bool defattr)
        {
            if (navigator == null)
            {
                throw new ArgumentNullException(nameof(navigator));
            }
            int iLevel = 0;

            navigator = navigator.Clone();

            while (true)
            {
                bool          mayHaveChildren = false;
                XPathNodeType nodeType        = navigator.NodeType;

                switch (nodeType)
                {
                case XPathNodeType.Element:
                    writer.WriteStartElement(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);

                    // Copy attributes
                    if (navigator.MoveToFirstAttribute())
                    {
                        do
                        {
                            writer.WriteStartAttribute(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
                            // copy string value to writer
                            writer.WriteString(navigator.Value);
                            writer.WriteEndAttribute();
                        } while (navigator.MoveToNextAttribute());
                        navigator.MoveToParent();
                    }

                    // Copy namespaces
                    if (navigator.MoveToFirstNamespace(XPathNamespaceScope.Local))
                    {
                        writer.WriteLocalNamespaces(navigator);
                        navigator.MoveToParent();
                    }
                    mayHaveChildren = true;
                    break;

                case XPathNodeType.Attribute:
                    // do nothing on root level attribute
                    break;

                case XPathNodeType.Text:
                    writer.WriteString(navigator.Value);
                    break;

                case XPathNodeType.SignificantWhitespace:
                case XPathNodeType.Whitespace:
                    writer.WriteWhitespace(navigator.Value);
                    break;

                case XPathNodeType.Root:
                    mayHaveChildren = true;
                    break;

                case XPathNodeType.Comment:
                    writer.WriteComment(navigator.Value);
                    break;

                case XPathNodeType.ProcessingInstruction:
                    writer.WriteProcessingInstruction(navigator.LocalName, navigator.Value);
                    break;

                case XPathNodeType.Namespace:
                    // do nothing on root level namespace
                    break;

                default:
                    Debug.Fail("Unmatched state in switch");
                    break;
                }

                if (mayHaveChildren)
                {
                    // If children exist, move down to next level
                    if (navigator.MoveToFirstChild())
                    {
                        iLevel++;
                        continue;
                    }
                    else
                    {
                        // EndElement
                        if (navigator.NodeType == XPathNodeType.Element)
                        {
                            if (navigator.IsEmptyElement)
                            {
                                writer.WriteEndElement();
                            }
                            else
                            {
                                writer.WriteFullEndElement();
                            }
                        }
                    }
                }

                // No children
                while (true)
                {
                    if (iLevel == 0)
                    {
                        // The entire subtree has been copied
                        return;
                    }

                    if (navigator.MoveToNext())
                    {
                        // Found a sibling, so break to outer loop
                        break;
                    }

                    // No siblings, so move up to previous level
                    iLevel--;
                    navigator.MoveToParent();

                    // EndElement
                    if (navigator.NodeType == XPathNodeType.Element)
                    {
                        writer.WriteFullEndElement();
                    }
                }
            }
        }
        /// <summary>
        /// Move to the next reader state.  Return false if that is ReaderState.Closed.
        /// </summary>
        public override bool Read()
        {
            _attrCount = -1;
            switch (_state)
            {
            case State.Error:
            case State.Closed:
            case State.EOF:
                return(false);

            case State.Initial:
                // Starting state depends on the navigator's item type
                _nav   = _navToRead;
                _state = State.Content;
                if (XPathNodeType.Root == _nav.NodeType)
                {
                    if (!_nav.MoveToFirstChild())
                    {
                        SetEOF();
                        return(false);
                    }
                    _readEntireDocument = true;
                }
                else if (XPathNodeType.Attribute == _nav.NodeType)
                {
                    _state = State.Attribute;
                }
                _nodeType = ToXmlNodeType(_nav.NodeType);
                break;

            case State.Content:
                if (_nav.MoveToFirstChild())
                {
                    _nodeType = ToXmlNodeType(_nav.NodeType);
                    _depth++;
                    _state = State.Content;
                }
                else if (_nodeType == XmlNodeType.Element &&
                         !_nav.IsEmptyElement)
                {
                    _nodeType = XmlNodeType.EndElement;
                    _state    = State.EndElement;
                }
                else
                {
                    goto case State.EndElement;
                }
                break;

            case State.EndElement:
                if (0 == _depth && !_readEntireDocument)
                {
                    SetEOF();
                    return(false);
                }
                else if (_nav.MoveToNext())
                {
                    _nodeType = ToXmlNodeType(_nav.NodeType);
                    _state    = State.Content;
                }
                else if (_depth > 0 && _nav.MoveToParent())
                {
                    Debug.Assert(_nav.NodeType == XPathNodeType.Element, _nav.NodeType.ToString() + " == XPathNodeType.Element");
                    _nodeType = XmlNodeType.EndElement;
                    _state    = State.EndElement;
                    _depth--;
                }
                else
                {
                    SetEOF();
                    return(false);
                }
                break;

            case State.Attribute:
            case State.AttrVal:
                if (!_nav.MoveToParent())
                {
                    SetEOF();
                    return(false);
                }
                _nodeType = ToXmlNodeType(_nav.NodeType);
                _depth--;
                if (_state == State.AttrVal)
                {
                    _depth--;
                }
                goto case State.Content;

            case State.InReadBinary:
                _state = _savedState;
                _readBinaryHelper.Finish();
                return(Read());
            }
            return(true);
        }
		private void GetNamespaceConsistentTree (XPathNavigator nav)
		{
			nav.MoveToFirstChild ();
			nav.MoveToFirstChild ();
			nav.MoveToNext ();
			Assert.AreEqual ("ns1", nav.GetNamespace (""), "#1." + nav.GetType ());
			nav.MoveToNext ();
			nav.MoveToNext ();
			Assert.AreEqual ("", nav.GetNamespace (""), "#2." + nav.GetType ());
		}
Example #22
0
        public virtual XmlNodeOrder ComparePosition(XPathNavigator nav)
        {
            if (IsSamePosition(nav))
            {
                return(XmlNodeOrder.Same);
            }

            if (IsDescendant(nav))
            {
                return(XmlNodeOrder.Before);
            }
            else if (nav.IsDescendant(this))
            {
                return(XmlNodeOrder.After);
            }

            XPathNavigator copy  = this.Clone();
            XPathNavigator other = nav.Clone();

            /* now, it gets expensive - we find the
             * closest common ancestor. But these two
             * might be from totally different places.
             *
             * Someone should re-implement this somewhere,
             * so that it is faster for XmlDocument.
             */
            int common     = 0;
            int otherDepth = 0;
            int copyDepth  = 0;

            copy.MoveToRoot();
            other.MoveToRoot();

            if (!copy.IsSamePosition(other))
            {
                return(XmlNodeOrder.Unknown);
            }

            /* what do you think ? I'm made of GC space ? */
            copy.MoveTo(this);
            other.MoveTo(nav);

            while (other.MoveToParent())
            {
                otherDepth++;
            }

            while (copy.MoveToParent())
            {
                copyDepth++;
            }

            common = (otherDepth > copyDepth) ? copyDepth : otherDepth;

            other.MoveTo(nav);
            copy.MoveTo(this);

            // traverse both till you get to depth == common
            for (; otherDepth > common; otherDepth--)
            {
                other.MoveToParent();
            }
            for (; copyDepth > common; copyDepth--)
            {
                copy.MoveToParent();
            }

            other.MoveTo(nav);
            copy.MoveTo(this);

            XPathNavigator copy1  = copy.Clone();
            XPathNavigator other1 = other.Clone();

            while (copy.IsSamePosition(other))
            {
                copy1.MoveTo(copy);
                other1.MoveTo(other);

                copy.MoveToParent();
                other.MoveToParent();
            }

            copy.MoveTo(copy1);
            other.MoveTo(other1);

            // Now copy & other are siblings and can be compared
            while (copy.MoveToNext())
            {
                if (copy.IsSamePosition(other))
                {
                    return(XmlNodeOrder.Before);
                }
            }

            return(XmlNodeOrder.After);
        }
Example #23
0
        public void ReadXml(XPathNavigator node, XmlResolver resolver)
        {
            if (node.NodeType == XPathNodeType.Element) {

            if (node.MoveToFirstAttribute()) {
               do {
                  switch (node.LocalName) {
                     case "media-type":
                        this.MediaType = node.Value;
                        break;

                     case "boundary":
                        this.Boundary = node.Value;
                        break;
                  }
               } while (node.MoveToNextAttribute());

               node.MoveToParent();
            }

            if (node.MoveToChild(XPathNodeType.Element)) {

               XPathHttpMultipartItem currentItem = null;

               do {
                  if (node.NamespaceURI == XPathHttpClient.Namespace) {

                     switch (node.LocalName) {
                        case "header":
                           if (currentItem == null) {
                              currentItem = new XPathHttpMultipartItem();
                           }

                           currentItem.Headers.Add(node.GetAttribute("name", ""), node.GetAttribute("value", ""));
                           break;

                        case "body":
                           if (currentItem == null) {
                              currentItem = new XPathHttpMultipartItem();
                           }

                           currentItem.Body = new XPathHttpBody();
                           currentItem.Body.ReadXml(node, resolver);

                           this.Items.Add(currentItem);
                           currentItem = null;
                           break;
                     }
                  }

               } while (node.MoveToNext(XPathNodeType.Element));

               node.MoveToParent();
            }
             }
        }
        internal override XPathNavigator advance()
        {
            if (_eLast == null)
            {
                XPathNavigator temp = null;
                _eLast = m_qyInput.advance();
                if (_eLast == null)
                {
                    return(null);
                }

                while (_eLast != null)
                {
                    _eLast = _eLast.Clone();
                    temp   = _eLast;
                    _eLast = m_qyInput.advance();
                    if (!temp.IsDescendant(_eLast))
                    {
                        break;
                    }
                }
                _eLast = temp;
            }
            while (true)
            {
                if (_first)
                {
                    _first = false;
                    if (_eLast.NodeType == XPathNodeType.Attribute || _eLast.NodeType == XPathNodeType.Namespace)
                    {
                        _eLast.MoveToParent();
                        if (_fMatchName)
                        {
                            _qy = _eLast.SelectDescendants(m_Name, m_URN, false);
                        }
                        else
                        {
                            _qy = _eLast.SelectDescendants(m_Type, false);
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            if (!_eLast.MoveToNext())
                            {
                                if (!_eLast.MoveToParent())
                                {
                                    _first = true;
                                    return(null);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (_fMatchName)
                        {
                            _qy = _eLast.SelectDescendants(m_Name, m_URN, true);
                        }
                        else
                        {
                            _qy = _eLast.SelectDescendants(m_Type, true);
                        }
                    }
                }
                if (_qy.MoveNext())
                {
                    _position++;
                    m_eNext = _qy.Current;
                    return(m_eNext);
                }
                else
                {
                    _first = true;
                }
            }
        }
Example #25
0
        /// <summary>
        /// Copy the navigator subtree to the raw writer.
        /// </summary>
        private void CopyNode(XPathNavigator nav) {
            XPathNodeType nodeType;
            int iLevel = 0;

            while (true) {
                if (CopyShallowNode(nav)) {
                    nodeType = nav.NodeType;
                    if (nodeType == XPathNodeType.Element) {
                        // Copy attributes
                        if (nav.MoveToFirstAttribute()) {
                            do {
                                CopyShallowNode(nav);
                            }
                            while (nav.MoveToNextAttribute());
                            nav.MoveToParent();
                        }

                        // Copy namespaces in document order (navigator returns them in reverse document order)
                        XPathNamespaceScope nsScope = (iLevel == 0) ? XPathNamespaceScope.ExcludeXml : XPathNamespaceScope.Local;
                        if (nav.MoveToFirstNamespace(nsScope)) {
                            CopyNamespaces(nav, nsScope);
                            nav.MoveToParent();
                        }

                        this.xwrt.StartElementContent();
                    }

                    // If children exist, move down to next level
                    if (nav.MoveToFirstChild()) {
                        iLevel++;
                        continue;
                    }
                    else {
                        // EndElement
                        if (nav.NodeType == XPathNodeType.Element)
                            this.xwrt.WriteEndElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                    }
                }

                // No children
                while (true) {
                    if (iLevel == 0) {
                        // The entire subtree has been copied
                        return;
                    }

                    if (nav.MoveToNext()) {
                        // Found a sibling, so break to outer loop
                        break;
                    }

                    // No siblings, so move up to previous level
                    iLevel--;
                    nav.MoveToParent();

                    // EndElement
                    if (nav.NodeType == XPathNodeType.Element)
                        this.xwrt.WriteFullEndElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                }
            }
        }
        /// <summary>
        /// Deep copy the subtree that is rooted at this navigator's current position to output.  If the current
        /// item is an element, copy all in-scope namespace nodes.
        /// </summary>
        private void CopyNode(XPathNavigator navigator) {
            XPathNodeType nodeType;
            int depthStart = this.depth;
            Debug.Assert(navigator != null);

            while (true) {
                if (StartCopy(navigator, this.depth == depthStart)) {
                    nodeType = navigator.NodeType;
                    Debug.Assert(nodeType == XPathNodeType.Element, "StartCopy should return true only for Element nodes.");

                    // Copy attributes
                    if (navigator.MoveToFirstAttribute()) {
                        do {
                            StartCopy(navigator, false);
                        }
                        while (navigator.MoveToNextAttribute());
                        navigator.MoveToParent();
                    }

                    // Copy namespaces in document order (navigator returns them in reverse document order)
                    CopyNamespaces(navigator, (this.depth - 1 == depthStart) ? XPathNamespaceScope.ExcludeXml : XPathNamespaceScope.Local);

                    StartElementContentUnchecked();

                    // If children exist, move down to next level
                    if (navigator.MoveToFirstChild())
                        continue;

                    EndCopy(navigator, (this.depth - 1) == depthStart);
                }

                // No children
                while (true) {
                    if (this.depth == depthStart) {
                        // The entire subtree has been copied
                        return;
                    }

                    if (navigator.MoveToNext()) {
                        // Found a sibling, so break to outer loop
                        break;
                    }

                    // No siblings, so move up to previous level
                    navigator.MoveToParent();

                    EndCopy(navigator, (this.depth - 1) == depthStart);
                }
            }
        }
        /// <summary>
        /// Copy a node by value to output according to Xslt rules:
        ///   1. Identity is never preserved
        ///   2. If the item is an Rtf, preserve serialization hints when copying.
        ///   3. If the item is a Root node, copy the children of the Root
        /// </summary>
        public void XsltCopyOf(XPathNavigator navigator) {
            RtfNavigator navRtf = navigator as RtfNavigator;

            if (navRtf != null) {
                // Copy Rtf
                navRtf.CopyToWriter(this);
            }
            else if (navigator.NodeType == XPathNodeType.Root) {
                // Copy children of root
                if (navigator.MoveToFirstChild()) {
                    do {
                        CopyNode(navigator);
                    }
                    while (navigator.MoveToNext());

                    navigator.MoveToParent();
                }
            }
            else {
                // Copy node
                CopyNode(navigator);
            }
        }
Example #28
0
		protected virtual ContentItem OnReadingItem(XPathNavigator navigator)
		{
			Dictionary<string, string> attributes = GetAttributes(navigator);

			ItemDefinition definition = FindDefinition(attributes);
			ContentItem item = engine.Resolve<ContentActivator>().CreateInstance(definition.ItemType, null);

			OnSettingDefaultAttributes(attributes, item);

			//authorizedRoles
			navigator.MoveToFirstChild();
			OnReadingAuthorizedRoles(navigator, item);

			//details
			navigator.MoveToNext();
			OnReadingDetails(navigator, item);

			//detailCollections
			navigator.MoveToNext();
			OnReadingDetailCollections(navigator, item);

			//children
			navigator.MoveToNext();
			OnReadingChildren(navigator, item);

			navigator.MoveToParent();
			return item;
		}
Example #29
0
		private void OnReadingChildren(XPathNavigator navigator, ContentItem item)
		{
			if (navigator.MoveToFirstChild())
			{
				do
				{
					ContentItem child = OnReadingItem(navigator);
					child.AddTo(item);
				} while (navigator.MoveToNext());
				navigator.MoveToParent();
			}
		}
        /// <summary>
        /// Reference: https://support.microsoft.com/en-us/kb/308343
        /// </summary>
        /// <param name="xNav"></param>
        public void TraverseChildren(XPathNavigator xNav)
        {
            xNav.MoveToFirstChild();

            do
            {
                //Find the first element.
                if (xNav.NodeType == XPathNodeType.Element)
                {

                    //Determine whether children exist.
                    if (xNav.HasChildren == true)
                    {
                        //Console.Write("The XML string for this child ");
                        //Console.WriteLine("is {0} = {1}", xNav.Name, xNav.Value);

                        switch (xNav.Name) {
                            case "timestamp_format" :
                                Config.TimestampFormat = xNav.Value;
                                break;
                            case "output_file_path":
                                Config.OutputFilePath = xNav.Value;
                                break;
                            case "screenshots_folder":
                                Config.ScreenshotsFolder = xNav.Value;
                                break;
                            case "screenshot_on_every_message":
                                Config.ScreenshotOnEveryMessage = Convert.ToBoolean(xNav.Value);
                                break;
                            case "screenshot_on_every_pass":
                                Config.ScreenshotOnEveryPass = Convert.ToBoolean(xNav.Value);
                                break;
                            case "screenshot_on_every_fail":
                                Config.ScreenshotOnEveryFail = Convert.ToBoolean(xNav.Value);
                                break;
                            case "screenshot_on_every_error":
                                Config.ScreenshotOnEveryError = Convert.ToBoolean(xNav.Value);
                                break;
                            case "force_throw_exception_on_assert_fail":
                                Config.ScreenshotOnEveryFail = Convert.ToBoolean(xNav.Value);
                                break;
                            case "on_click_event":
                                _ParentNode = "OnClick";
                                break;
                            case "log_function_start":
                                if (_ParentNode == "OnClick")
                                    Config.OnClick_LogFunctionStart = Convert.ToBoolean(xNav.Value);
                                break;
                            case "log_function_end":
                                if (_ParentNode == "OnClick")
                                    Config.OnClick_LogFunctionEnd = Convert.ToBoolean(xNav.Value);
                                break;
                            case "screenshot_on_start":
                                if (_ParentNode == "OnClick")
                                    Config.OnClick_ScreenshotOnStart = Convert.ToBoolean(xNav.Value);
                                break;
                            case "screenshot_on_end":
                                if (_ParentNode == "OnClick")
                                    Config.OnClick_ScreenshotOnEnd = Convert.ToBoolean(xNav.Value);
                                break;                             

                            default:
                                break;

                        } // end switch

                        TraverseChildren(xNav);
                        xNav.MoveToParent();

                    }
                }
            } while (xNav.MoveToNext());
        }
Example #31
0
        bool IReflectorPersistance.Load(System.Xml.XPath.XPathNavigator r)
        {
            if (r.NodeType == XPathNodeType.Element)
            {
                osalot.AssemblyTracker tracker = new osalot.AssemblyTracker();
                string location = null;
                switch (r.Name)
                {
                case "Plugins":
                    bool everokay = false;
                    bool okay;
                    for (okay = r.MoveToFirstAttribute(); okay; okay = r.MoveToNextAttribute())
                    {
                        everokay = true;
                        switch (r.Name)
                        {
                        case "Location":
                            location = r.Value;
                            break;
                        }
                    }
                    if (everokay)
                    {
                        r.MoveToParent();
                    }

                    everokay = false;
                    for (okay = r.MoveToFirstChild(); okay; okay = r.MoveToNext())
                    {
                        everokay = true;
                        switch (r.Name)
                        {
                        case "System Mask":
                            tracker.allow_on_system.Add(r.Value);
                            break;
                        }
                    }
                    if (everokay)
                    {
                        r.MoveToParent();
                    }
                    if (tracker.allow_on_system.Count == 0)
                    {
                        core_common.LoadAssembly(location, tracker);
                    }
                    else
                    {
                        foreach (String s in tracker.allow_on_system)
                        {
                            Match m = Regex.Match(SystemInformation.ComputerName, s);
                            if (m.Success)
                            {
                                core_common.LoadAssembly(location, tracker);
                                break;
                            }
                        }
                    }
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Example #32
0
        virtual bool MoveToFollowing(string localName,
                                     string namespaceURI, XPathNavigator end)
        {
            if (localName == null)
            {
                throw new ArgumentNullException("localName");
            }
            if (namespaceURI == null)
            {
                throw new ArgumentNullException("namespaceURI");
            }
            localName = NameTable.Get(localName);
            if (localName == null)
            {
                return(false);
            }
            namespaceURI = NameTable.Get(namespaceURI);
            if (namespaceURI == null)
            {
                return(false);
            }

            XPathNavigator nav = Clone();

            switch (nav.NodeType)
            {
            case XPathNodeType.Attribute:
            case XPathNodeType.Namespace:
                nav.MoveToParent();
                break;
            }
            do
            {
                if (!nav.MoveToFirstChild())
                {
                    do
                    {
                        if (!nav.MoveToNext())
                        {
                            if (!nav.MoveToParent())
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            break;
                        }
                    } while (true);
                }
                if (end != null && end.IsSamePosition(nav))
                {
                    return(false);
                }
                if (object.ReferenceEquals(localName, nav.LocalName) &&
                    object.ReferenceEquals(namespaceURI, nav.NamespaceURI))
                {
                    MoveTo(nav);
                    return(true);
                }
            } while (true);
        }
Example #33
0
        // Copies the current node from the given XPathNavigator to the writer (including child nodes).
        public virtual void WriteNode(XPathNavigator navigator, bool defattr)
        {
            if (navigator == null)
            {
                throw new ArgumentNullException(nameof(navigator));
            }
            int iLevel = 0;

            navigator = navigator.Clone();

            while (true)
            {
                bool mayHaveChildren = false;
                XPathNodeType nodeType = navigator.NodeType;

                switch (nodeType)
                {
                    case XPathNodeType.Element:
                        WriteStartElement(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);

                        // Copy attributes
                        if (navigator.MoveToFirstAttribute())
                        {
                            do
                            {
                                IXmlSchemaInfo schemaInfo = navigator.SchemaInfo;
                                if (defattr || (schemaInfo == null || !schemaInfo.IsDefault))
                                {
                                    WriteStartAttribute(navigator.Prefix, navigator.LocalName, navigator.NamespaceURI);
                                    // copy string value to writer
                                    WriteString(navigator.Value);
                                    WriteEndAttribute();
                                }
                            } while (navigator.MoveToNextAttribute());
                            navigator.MoveToParent();
                        }

                        // Copy namespaces
                        if (navigator.MoveToFirstNamespace(XPathNamespaceScope.Local))
                        {
                            WriteLocalNamespaces(navigator);
                            navigator.MoveToParent();
                        }
                        mayHaveChildren = true;
                        break;
                    case XPathNodeType.Attribute:
                        // do nothing on root level attribute
                        break;
                    case XPathNodeType.Text:
                        WriteString(navigator.Value);
                        break;
                    case XPathNodeType.SignificantWhitespace:
                    case XPathNodeType.Whitespace:
                        WriteWhitespace(navigator.Value);
                        break;
                    case XPathNodeType.Root:
                        mayHaveChildren = true;
                        break;
                    case XPathNodeType.Comment:
                        WriteComment(navigator.Value);
                        break;
                    case XPathNodeType.ProcessingInstruction:
                        WriteProcessingInstruction(navigator.LocalName, navigator.Value);
                        break;
                    case XPathNodeType.Namespace:
                        // do nothing on root level namespace
                        break;
                    default:
                        Debug.Assert(false);
                        break;
                }

                if (mayHaveChildren)
                {
                    // If children exist, move down to next level
                    if (navigator.MoveToFirstChild())
                    {
                        iLevel++;
                        continue;
                    }
                    else
                    {
                        // EndElement
                        if (navigator.NodeType == XPathNodeType.Element)
                        {
                            if (navigator.IsEmptyElement)
                            {
                                WriteEndElement();
                            }
                            else
                            {
                                WriteFullEndElement();
                            }
                        }
                    }
                }

                // No children
                while (true)
                {
                    if (iLevel == 0)
                    {
                        // The entire subtree has been copied
                        return;
                    }

                    if (navigator.MoveToNext())
                    {
                        // Found a sibling, so break to outer loop
                        break;
                    }

                    // No siblings, so move up to previous level
                    iLevel--;
                    navigator.MoveToParent();

                    // EndElement
                    if (navigator.NodeType == XPathNodeType.Element)
                        WriteFullEndElement();
                }
            }
        }
Example #34
0
        public virtual XmlNodeOrder ComparePosition(XPathNavigator nav)
        {
            if (IsSamePosition(nav))
            {
                return(XmlNodeOrder.Same);
            }

            // quick check for direct descendant
            if (IsDescendant(nav))
            {
                return(XmlNodeOrder.Before);
            }

            // quick check for direct ancestor
            if (nav.IsDescendant(this))
            {
                return(XmlNodeOrder.After);
            }

            XPathNavigator nav1 = Clone();
            XPathNavigator nav2 = nav.Clone();

            // check if document instance is the same.
            nav1.MoveToRoot();
            nav2.MoveToRoot();
            if (!nav1.IsSamePosition(nav2))
            {
                return(XmlNodeOrder.Unknown);
            }
            nav1.MoveTo(this);
            nav2.MoveTo(nav);

            int depth1 = 0;

            while (nav1.MoveToParent())
            {
                depth1++;
            }
            nav1.MoveTo(this);
            int depth2 = 0;

            while (nav2.MoveToParent())
            {
                depth2++;
            }
            nav2.MoveTo(nav);

            // find common parent depth
            int common = depth1;

            for (; common > depth2; common--)
            {
                nav1.MoveToParent();
            }
            for (int i = depth2; i > common; i--)
            {
                nav2.MoveToParent();
            }
            while (!nav1.IsSamePosition(nav2))
            {
                nav1.MoveToParent();
                nav2.MoveToParent();
                common--;
            }

            // For each this and target, move to the node that is
            // ancestor of the node and child of the common parent.
            nav1.MoveTo(this);
            for (int i = depth1; i > common + 1; i--)
            {
                nav1.MoveToParent();
            }
            nav2.MoveTo(nav);
            for (int i = depth2; i > common + 1; i--)
            {
                nav2.MoveToParent();
            }

            // Those children of common parent are comparable.
            // namespace nodes precede to attributes, and they
            // precede to other nodes.
            if (nav1.NodeType == XPathNodeType.Namespace)
            {
                if (nav2.NodeType != XPathNodeType.Namespace)
                {
                    return(XmlNodeOrder.Before);
                }
                while (nav1.MoveToNextNamespace())
                {
                    if (nav1.IsSamePosition(nav2))
                    {
                        return(XmlNodeOrder.Before);
                    }
                }
                return(XmlNodeOrder.After);
            }
            if (nav2.NodeType == XPathNodeType.Namespace)
            {
                return(XmlNodeOrder.After);
            }
            if (nav1.NodeType == XPathNodeType.Attribute)
            {
                if (nav2.NodeType != XPathNodeType.Attribute)
                {
                    return(XmlNodeOrder.Before);
                }
                while (nav1.MoveToNextAttribute())
                {
                    if (nav1.IsSamePosition(nav2))
                    {
                        return(XmlNodeOrder.Before);
                    }
                }
                return(XmlNodeOrder.After);
            }
            while (nav1.MoveToNext())
            {
                if (nav1.IsSamePosition(nav2))
                {
                    return(XmlNodeOrder.Before);
                }
            }
            return(XmlNodeOrder.After);
        }
 // Begin: GetNodeInfo
 private void GetNodeInfo(XPathNavigator nav1)
 {
   if (nav1 != null && nav1.Name != null && nav1.Name.ToString(CultureInfo.CurrentCulture).Equals("images", StringComparison.CurrentCulture))
   {
     using (var xmlReader = nav1.ReadSubtree())
     {
       var searchResults = new SearchResults();
       while (xmlReader.Read())
       {
         if (xmlReader.NodeType == XmlNodeType.Element)
         {
           switch (xmlReader.Name)
           {
             case "id":
               searchResults = new SearchResults();
               searchResults.Id = xmlReader.ReadString();
               continue;
             case "album":
               searchResults.Album = xmlReader.ReadString();
               continue;
             case "title":
               searchResults.Title = xmlReader.ReadString();
               continue;
             case "alias":
               searchResults.AddAlias(xmlReader.ReadString());
               continue;
             case "mbid":
               searchResults.MBID = xmlReader.ReadString();
               continue;
             case "votes":
               alSearchResults.Add(searchResults);
               continue;
             default:
               continue;
           }
         }
       }
     }
   }
   if (nav1 != null && nav1.HasChildren)
   {
     nav1.MoveToFirstChild();
     while (nav1.MoveToNext())
     {
       GetNodeInfo(nav1);
       nav1.MoveToParent();
     }
   }
   else
   {
     if (nav1 == null || !nav1.MoveToNext())
       return;
     GetNodeInfo(nav1);
   }
 }
Example #36
0
        /// <summary>
        /// Move to the next reader state.  Return false if that is ReaderState.Closed.
        /// </summary>
        public override bool Read()
        {
            _attrCount = -1;
            switch (_state)
            {
                case State.Error:
                case State.Closed:
                case State.EOF:
                    return false;

                case State.Initial:
                    // Starting state depends on the navigator's item type
                    _nav = _navToRead;
                    _state = State.Content;
                    if (XPathNodeType.Root == _nav.NodeType)
                    {
                        if (!_nav.MoveToFirstChild())
                        {
                            SetEOF();
                            return false;
                        }
                        _readEntireDocument = true;
                    }
                    else if (XPathNodeType.Attribute == _nav.NodeType)
                    {
                        _state = State.Attribute;
                    }
                    _nodeType = ToXmlNodeType(_nav.NodeType);
                    break;

                case State.Content:
                    if (_nav.MoveToFirstChild())
                    {
                        _nodeType = ToXmlNodeType(_nav.NodeType);
                        _depth++;
                        _state = State.Content;
                    }
                    else if (_nodeType == XmlNodeType.Element
                        && !_nav.IsEmptyElement)
                    {
                        _nodeType = XmlNodeType.EndElement;
                        _state = State.EndElement;
                    }
                    else
                        goto case State.EndElement;
                    break;

                case State.EndElement:
                    if (0 == _depth && !_readEntireDocument)
                    {
                        SetEOF();
                        return false;
                    }
                    else if (_nav.MoveToNext())
                    {
                        _nodeType = ToXmlNodeType(_nav.NodeType);
                        _state = State.Content;
                    }
                    else if (_depth > 0 && _nav.MoveToParent())
                    {
                        Debug.Assert(_nav.NodeType == XPathNodeType.Element, _nav.NodeType.ToString() + " == XPathNodeType.Element");
                        _nodeType = XmlNodeType.EndElement;
                        _state = State.EndElement;
                        _depth--;
                    }
                    else
                    {
                        SetEOF();
                        return false;
                    }
                    break;

                case State.Attribute:
                case State.AttrVal:
                    if (!_nav.MoveToParent())
                    {
                        SetEOF();
                        return false;
                    }
                    _nodeType = ToXmlNodeType(_nav.NodeType);
                    _depth--;
                    if (_state == State.AttrVal)
                        _depth--;
                    goto case State.Content;
                case State.InReadBinary:
                    _state = _savedState;
                    _readBinaryHelper.Finish();
                    return Read();
            }
            return true;
        }
        protected override IPredicate BuildPredicate(XPathNavigator predicateElement, bool inHead, bool resolveImmediatly)
        {
            IPredicate predicate;
            string predicateName = predicateElement.Name;
            string predicateValue = predicateElement.Value;

            switch(predicateName) {
                // --------- IND predicates --------
                case "Ind":
                    string predicateURI = predicateElement.GetAttribute("uri", String.Empty).ToLower();

                    switch(predicateURI) {
                        case "nxbre://expression":
                            if (inHead) {
                                if (resolveImmediatly) predicate = new Individual(Compilation.Evaluate(predicateValue));
                                else predicate = new Formula(Formula.FormulaResolutionType.NxBRE,
                                                             Binder,
                                                             predicateValue);
                            }
                            else {
                                predicate = new Function(Function.FunctionResolutionType.Binder,
                                                         predicateValue,
                                                         new ExpressionEvaluator(predicateValue),
                                                       	 String.Empty,
                                                      	 String.Empty);
                            }
                            break;

                        case "nxbre://operator":
                            // NxBRE operators must follow this pattern: operator(uniqueargument)
                            ObjectPair operatorCall = Parameter.ParseOperatorCall(predicateValue);
                            predicate = new Function(Function.FunctionResolutionType.NxBRE,
                                                     predicateValue,
                                                     null,
                                                     (string)operatorCall.First,
                                                                             (string)operatorCall.Second);
                            break;

                        case "nxbre://binder":
                            if (Binder == null) throw new BREException("No binder available for Individual: " + predicateValue);

                            if (inHead) predicate = new Formula(Formula.FormulaResolutionType.Binder,
                                                                            Binder,
                                                   							predicateValue);
                            else predicate = Binder.AnalyzeIndividualPredicate(new Individual(predicateValue));

                            break;

                        case "":
                            predicate = new Individual(predicateValue);
                            break;

                        default:
                            // there is a predicateURI but it is not recognized by the engine so we assimilate it as
                            // a web reference
                            predicate = new Individual(new HyperLink(predicateValue, predicateURI));
                            break;
                    }
                    break;

            // --------- VAR predicates --------
            case "Var":
                predicate = new Variable(predicateValue);
                break;

            // --------- DATA predicates --------
            case "Data":
                string schemaType = predicateElement.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance");
                if (schemaType != String.Empty) {
                    // remove any preceding namespace, like in "xs:string"
                    if (schemaType.IndexOf(':')>=0) schemaType = schemaType.Split(':')[1];

                    // this is a strongly typed individual
                    predicate = new Individual(Xml.ToClr(predicateValue, schemaType), schemaType);
                }
                else {
                    // this is just a string based predicate, using Data was not so wise...
                    predicate = new Individual(predicateValue);
                }

                break;

            // --------- SLOT predicates --------
            case "slot":
                // the first child must be an Ind, we do not support other slot name holders
                if (predicateElement.MoveToFirstChild()) {
                    if (predicateElement.Name != "Ind") throw new BREException("Only Ind is accepted as a slot name holder");
                    string slotName = predicateElement.Value;
                    if (!predicateElement.MoveToNext()) throw new BREException("A slot should contain two children");
                    predicate = new Slot(slotName, BuildPredicate(predicateElement, inHead, resolveImmediatly));
                }
                else {
                    throw new BREException("A slot can not be empty");
                }

                break;

            // --------- UNKNOWN predicates --------
            default:
                throw new BREException("Unsupported predicate type: " + predicateName);
            }

            return predicate;
        }
        static void NavigatorValues(XPathNavigator nav, bool native)
        {
            // in non-native we can't have Value dump everything, else
            // we'd dump the entire database? Makes not much sense.

            Assert.AreEqual(native ? "\n        blah\n            blah\n        bam\n        " : string.Empty, nav.Value.Lf()); // !!
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual("root", nav.Name);
            Assert.AreEqual(native ? "\n        blah\n            blah\n        bam\n        " : string.Empty, nav.Value.Lf()); // !!
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual("wrap", nav.Name);
            Assert.AreEqual(native ? "\n        blah\n            blah\n        bam\n        " : string.Empty, nav.Value.Lf()); // !!

            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual("item1", nav.Name);
            Assert.AreEqual(string.Empty, nav.Value);
            Assert.IsFalse(nav.MoveToFirstChild());

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("item2", nav.Name);
            Assert.AreEqual(string.Empty, nav.Value);
            Assert.IsFalse(nav.MoveToFirstChild()); // !!

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("item2a", nav.Name);
            Assert.AreEqual(string.Empty, nav.Value);
            Assert.IsFalse(nav.MoveToFirstChild()); // !!

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("item2b", nav.Name);
            Assert.AreEqual(string.Empty, nav.Value);
            Assert.IsFalse(nav.MoveToFirstChild()); // !!

            // we have no way to tell the navigable that a value is CDATA
            // so the rule is, if it's null it's not there, anything else is there
            // and the filtering has to be done when building the content

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("item2c", nav.Name);
            Assert.AreEqual("\n        ", nav.Value.Lf()); // ok since it's a property
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(XPathNodeType.Text, nav.NodeType);
            Assert.AreEqual(string.Empty, nav.Name);
            Assert.AreEqual("\n        ", nav.Value.Lf());
            Assert.IsTrue(nav.MoveToParent());

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("item3", nav.Name);
            Assert.AreEqual("blah", nav.Value); // ok since it's a property
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(XPathNodeType.Text, nav.NodeType);
            Assert.AreEqual(string.Empty, nav.Name);
            Assert.AreEqual("blah", nav.Value);
            Assert.IsTrue(nav.MoveToParent());

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("item3a", nav.Name);
            Assert.AreEqual("\n            blah\n        ", nav.Value.Lf()); // ok since it's a property
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(XPathNodeType.Text, nav.NodeType);
            Assert.AreEqual(string.Empty, nav.Name);
            Assert.AreEqual("\n            blah\n        ", nav.Value.Lf());
            Assert.IsTrue(nav.MoveToParent());

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("item4", nav.Name);
            Assert.AreEqual("bam", nav.Value); // ok since it's a property
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual("subitem", nav.Name);
            Assert.AreEqual("bam", nav.Value); // ok since we're in a fragment
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(XPathNodeType.Text, nav.NodeType);
            Assert.AreEqual(string.Empty, nav.Name);
            Assert.AreEqual("bam", nav.Value);
            Assert.IsFalse(nav.MoveToNext());
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual("subitem", nav.Name);
            Assert.IsFalse(nav.MoveToNext());
            Assert.IsTrue(nav.MoveToParent());
            Assert.AreEqual("item4", nav.Name);

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("item5", nav.Name);
            Assert.AreEqual("\n        ", nav.Value.Lf());
            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual(XPathNodeType.Text, nav.NodeType);
            Assert.AreEqual("\n        ", nav.Value.Lf());
        }
        private XmlNodeOrder CompareSiblings(XPathNavigator n1, XPathNavigator n2)
        {
            int num = 0;
            switch (n1.NodeType)
            {
                case XPathNodeType.Attribute:
                    num++;
                    break;

                case XPathNodeType.Namespace:
                    break;

                default:
                    num += 2;
                    break;
            }
            switch (n2.NodeType)
            {
                case XPathNodeType.Attribute:
                    num--;
                    if (num == 0)
                    {
                        while (n1.MoveToNextAttribute())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;

                case XPathNodeType.Namespace:
                    if (num == 0)
                    {
                        while (n1.MoveToNextNamespace())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;

                default:
                    num -= 2;
                    if (num == 0)
                    {
                        while (n1.MoveToNext())
                        {
                            if (n1.IsSamePosition(n2))
                            {
                                return XmlNodeOrder.Before;
                            }
                        }
                    }
                    break;
            }
            if (num >= 0)
            {
                return XmlNodeOrder.After;
            }
            return XmlNodeOrder.Before;
        }
		/// <summary>
		/// Reads an XmlConfigurationCategoryCollection using the specified XPathNavigator
		/// </summary>
		/// <param name="navigator"></param>
		/// <returns></returns>
		private XmlConfigurationCategoryCollection ReadCategories(XPathNavigator navigator, XmlConfigurationCategoryCollection categories)
		{			
			if (navigator.HasChildren)
			{
				if (navigator.MoveToFirstChild())
				{
					// is this element a category node?
					if (string.Compare(navigator.Name, @"Category", true) == 0)
					{
						// so read it
						XmlConfigurationCategory category = new XmlConfigurationCategory();
						category.BeginInit();
						category.Parent = categories;
						
						this.ReadCategory(navigator, category);						
						
						// and add it to the current collection of categories
						categories.Add(category);
						category.EndInit();
					}					
				}
			}

			while (navigator.MoveToNext())
			{	
				// is this element a category node?
				if (string.Compare(navigator.Name, @"Category", true) == 0)
				{
					// so read it
					XmlConfigurationCategory category = new XmlConfigurationCategory();
					category.BeginInit();
					category.Parent = categories;
					
					this.ReadCategory(navigator, category);					

					// and add it to the current collection of categories
					categories.Add(category);
					category.EndInit();
				}
			}
			
			return categories;
		}
        private void WriteNextNode(XmlWriter writer, XPathNavigator nav, bool iterateSiblings)
        {
            if (nav.Name == "ScatterFile")
            {
                writer.WriteStartElement(nav.Name, nav.NamespaceURI);
            }
            else
            {
                writer.WriteStartElement(nav.Name);
            }

            XPathNavigator attrib = nav.CreateNavigator();
            if (attrib.MoveToFirstAttribute())
            {
                do
                {
                    writer.WriteAttributeString(attrib.Name, attrib.Value);
                }
                while (attrib.MoveToNextAttribute());
            }

            if (nav.Name == "LoadRegion")
            {
                string lrName = nav.GetAttribute("Name", "");

                foreach (ExecRegion er in (m_execRegionOrderMap[lrName] as SortedList).Values)
                {
                    WriteNextNode(writer, m_execRegionsToNavNode[lrName + ":" + er.Name] as XPathNavigator, false);
                }
            }
            /*
            else if (nav.Name == "ExecRegion")
            {
                string erName = nav.GetAttribute("Name", "");

                foreach (FileMapping fm in (m_symOrderMap[erName] as SortedList).Values)
                {
                    WriteNextNode(writer, m_symToNavNode[erName + ":" + fm.Name] as XPathNavigator, false);
                }
            }
            */
            else
            {
                XPathNodeIterator children = nav.SelectChildren(XPathNodeType.Element);
                while (children.MoveNext())
                {
                    WriteNextNode(writer, children.Current, iterateSiblings);
                }
            }
            writer.WriteEndElement();

            if (iterateSiblings && nav.MoveToNext())
            {
                WriteNextNode(writer, nav, iterateSiblings);
            }
        }