MoveToParent() public abstract méthode

public abstract MoveToParent ( ) : bool
Résultat bool
		public static string GetXPath (XPathNavigator n)
		{
			switch (n.NodeType) {
				case XPathNodeType.Root: return "/";
				case XPathNodeType.Attribute: {
					string ret = "@" + n.Name;
					n.MoveToParent ();
					string s = GetXPath (n);
					return s + (s == "/" ? "" : "/") + ret;
				}

				case XPathNodeType.Element: {
					string ret = n.Name;
					int i = 1;
					while (n.MoveToPrevious ()) {
						if (n.NodeType == XPathNodeType.Element && n.Name == ret)
							i++;
					}
					ret += "[" + i + "]";
					if (n.MoveToParent ()) {
						string s = GetXPath (n);
						return s + (s == "/" ? "" : "/") + ret;
					}
				}
				break;
			}
			throw new Exception ("node type not supported for editing");
			
		}
Exemple #2
0
        public CreateCone(System.Xml.XPath.XPathNavigator navigator, GEMSSingle parent)
            : base(navigator, parent)
        {
            alineAxis = (Axis)Enum.Parse(typeof(Axis), navigator.GetAttribute("axis", string.Empty));

            //Bottom radius of cylinder
            navigator.MoveToChild("BottomRadius", string.Empty);
            bottomRadius = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent( );

            //Top radius of cylinder
            navigator.MoveToChild("TopRadius", string.Empty);
            topRadius = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent( );

            //Height of cylinder
            navigator.MoveToChild("Height", string.Empty);
            height = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent( );

            //Center of cylinder
            navigator.MoveToChild("Center", string.Empty);
            center   = new Vector3WithUnit( );
            center.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty));
            center.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty));
            center.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty));
            navigator.MoveToParent( );
        }
Exemple #3
0
        public CreateCuboid(System.Xml.XPath.XPathNavigator navigator, GEMSSingle parent)
            : base(navigator, parent)
        {
            //Width of box
            navigator.MoveToChild("Width", string.Empty);
            width = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent();

            //Depth of box
            navigator.MoveToChild("Depth", string.Empty);
            depth = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent();

            //Height of box
            navigator.MoveToChild("Height", string.Empty);
            height = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent();

            //Reference point of box
            navigator.MoveToChild("RefPoint", string.Empty);
            refPoint   = new Vector3WithUnit();
            refPoint.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty));
            refPoint.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty));
            refPoint.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty));
            navigator.MoveToParent();
        }
Exemple #4
0
        public void ReadXml(XPathNavigator node)
        {
            if (node.MoveToFirstAttribute()) {

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

                  switch (node.LocalName) {
                     case "address":
                        this.Address = node.Value;
                        break;

                     case "display-name":
                        this.DisplayName = node.Value;
                        break;

                     default:
                        break;
                  }
               }

            } while (node.MoveToNextAttribute());

            node.MoveToParent();
             }
        }
Exemple #5
0
        public ParameterNode(XPathNavigator aNode)
        {

            valueNode = String.Empty;
            typeNode = String.Empty;
            ruleValueNode = String.Empty;
            name = String.Empty;

            if (aNode.MoveToFirstAttribute())
            {
                do
                {
                    string nodeName = aNode.Name;
                    switch (nodeName)
                    {
                        case PARAMETER_ATTRS.NAME:
                            name = aNode.Value;
                            break;
                        case PARAMETER_ATTRS.VALUE:
                            valueNode = aNode.Value;
                            break;
                        case PARAMETER_ATTRS.TYPE:
                            typeNode = aNode.Value;
                            break;
                        case PARAMETER_ATTRS.RULE_VALUE:
                            ruleValueNode = aNode.Value;
                            break;
                    }
                } while (aNode.MoveToNextAttribute());
                aNode.MoveToParent();
            }

        }
Exemple #6
0
        public CreateSphere(System.Xml.XPath.XPathNavigator navigator, GEMSSingle parent)
            : base(navigator, parent)
        {
            //Radius of sphere
            navigator.MoveToChild("Radius", string.Empty);
            radius = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent();

            //Center of sphere
            navigator.MoveToChild("Center", string.Empty);
            center   = new Vector3WithUnit();
            center.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty));
            center.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty));
            center.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty));
            navigator.MoveToParent();
        }
        static void FullName(XPathNavigator navigator, StringBuilder s)
        {
            if (navigator.NodeType == XPathNodeType.Root)
            return;

             string name = navigator.Name;
             string value = null;
             XPathNodeType nodeType = navigator.NodeType;
             if (nodeType == XPathNodeType.Attribute)
            value = navigator.Value;

             int same = 0;
             int position = 0;
             XPathNavigator sibling = navigator.Clone();
             sibling.MoveToFirst();
             do
             {
            if (sibling.NodeType == nodeType && sibling.Name == name)
            {
               if (sibling.IsSamePosition(navigator))
                  position = same;
               else
                  ++same;
            }
             } while (sibling.MoveToNext());

             if (navigator.MoveToParent())
            FullName(navigator, s);

             switch (nodeType)
             {
            case XPathNodeType.Element:
               s.Append('/');
               s.Append(name);
               if (same != 0)
               {
                  s.Append('[');
                  s.Append((position + 1).ToString(CultureInfo.InvariantCulture));
                  s.Append(']');
               }
               break;
            case XPathNodeType.Attribute:
               s.Append("[@");
               s.Append(name);
               if (same != 0)
                  s.AppendFormat(" = '{0}'", value);
               s.Append("]");
               break;

            case XPathNodeType.Comment:
            case XPathNodeType.Namespace:
            case XPathNodeType.ProcessingInstruction:
            case XPathNodeType.Root:
            case XPathNodeType.Text:
            case XPathNodeType.Whitespace:
            default:
               throw new NotSupportedException();
             }
        }
Exemple #8
0
        public CreateRound(System.Xml.XPath.XPathNavigator navigator, GEMSSingle parent)
            : base(navigator, parent)
        {
            alineAxis = (Axis)Enum.Parse(typeof(Axis), navigator.GetAttribute("axis", string.Empty));

            //Radius of circle
            navigator.MoveToChild("Radius", string.Empty);
            radius = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent();

            //Center of circle
            navigator.MoveToChild("Center", string.Empty);
            center   = new Vector3WithUnit();
            center.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty));
            center.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty));
            center.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty));
            navigator.MoveToParent();
        }
        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();
            }
             }
        }
 private string GetChildNodesValue(XPathNavigator nav, string nodeName)
 {
     string value = string.Empty;
     if (nav.MoveToChild(nodeName, ""))
     {
         value = nav.Value;
         nav.MoveToParent();
     }
     return value;
 }
Exemple #11
0
 public CreatePoint(System.Xml.XPath.XPathNavigator navigator, GEMSSingle parent)
     : base(navigator, parent)
 {
     //Position of Point
     navigator.MoveToChild("Position", string.Empty);
     position   = new Vector3WithUnit();
     position.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty));
     position.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty));
     position.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty));
     navigator.MoveToParent();
 }
 public static void SetOrCreateXmlAttribute(XPathNavigator node, string localName, string namespaceURI, string value)
 {
     if (node.MoveToAttribute(localName, namespaceURI))
     {
         node.SetValue(value);
         node.MoveToParent();
     }
     else
     {
         node.CreateAttribute("", localName, namespaceURI, value);
     }
 }
Exemple #13
0
 public static Dictionary<string, string> GetAttributes(XPathNavigator navigator)
 {
     if (!navigator.MoveToFirstAttribute())
         throw new DeserializationException("Node has no attributes: " + navigator.Name);
     Dictionary<string, string> attributes = new Dictionary<string, string>();
     do
     {
         attributes.Add(navigator.Name, navigator.Value);
     } while (navigator.MoveToNextAttribute());
     navigator.MoveToParent();
     return attributes;
 }
Exemple #14
0
        public static IEnumerable<XPathNavigator> EnumerateChildren(XPathNavigator navigator)
        {
            if (navigator.MoveToFirstChild())
            {
                do
                {
                    yield return navigator;
                } while (navigator.MoveToNext());

                navigator.MoveToParent();
            }
        }
Exemple #15
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();
         }
      }
Exemple #16
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();
        }
Exemple #17
0
        public CreateRectangle(System.Xml.XPath.XPathNavigator navigator, GEMSSingle parent)
            : base(navigator, parent)
        {
            alineAxis = (Axis)Enum.Parse(typeof(Axis), navigator.GetAttribute("axis", string.Empty));

            //Width of rectangle
            navigator.MoveToChild("Width", string.Empty);
            width = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent();

            //Height of rectangle
            navigator.MoveToChild("Height", string.Empty);
            height = new Length(navigator.GetAttribute("value", string.Empty), navigator.GetAttribute("unit", string.Empty));
            navigator.MoveToParent();

            //Reference point of rectangle
            navigator.MoveToChild("RefPoint", string.Empty);
            refPoint   = new Vector3WithUnit();
            refPoint.X = new Length(navigator.GetAttribute("x", string.Empty), navigator.GetAttribute("ux", string.Empty));
            refPoint.Y = new Length(navigator.GetAttribute("y", string.Empty), navigator.GetAttribute("uy", string.Empty));
            refPoint.Z = new Length(navigator.GetAttribute("z", string.Empty), navigator.GetAttribute("uz", string.Empty));
            navigator.MoveToParent();
        }
Exemple #18
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;
        }
 private void AddAttributeList(XPathNavigator nav, ArrayList attrs)
 {
     if (nav.HasAttributes)
     {
         nav.MoveToFirstAttribute();
         do
         {
             if (!attrs.Contains(nav.Name))
             {
                 attrs.Add(nav.Name);
             }
         }
         while (nav.MoveToNextAttribute());
         nav.MoveToParent();
     }
 }
        /// <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);
            }
        }
        public IList<string> GrabBackDropUrls(XPathNavigator nav)
        {
            List<string> urls = new List<string>();
            XPathNodeIterator nIter = nav.SelectChildren("backdrop", "");
            if (nav.MoveToFollowing("backdrop", ""))
            {
                XPathNavigator localNav = nav.CreateNavigator();
                nav.MoveToParent();
                for (int i = 0; i < nIter.Count; i++)
                {
                    if (localNav.GetAttribute("size", "").ToUpperInvariant().Equals("original".ToUpperInvariant()))
                        urls.Add(localNav.Value);

                    localNav.MoveToNext();
                }
            }
            return urls;
        }
Exemple #22
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();
                }
            }
        }
        /// <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();
        }
Exemple #24
0
 override internal XPathNavigator advancefordescendant() {
     XPathNavigator result = null;
     ArrayList elementList = new ArrayList();
     int i = 0;
     _eLast = m_qyInput.advance();
     while (_eLast != null){
         for(i = 0; i < elementList.Count; i++ ) {
             if (  ((XPathNavigator)elementList[i]).IsDescendant(_eLast)) {
                break;
             }
         }
         if ( i == _pathstack.Count )
             break;
         _eLast = m_qyInput.advance();
     }
     
     if (_eLast == null )
         return null;
     result = _eLast.Clone();
     while (true) {
         if (_fMatchSelf)
             if (matches( _eLast))
                 result.MoveTo(_eLast);
         if (!_eLast.MoveToParent())
         {
             elementList.Add(result);
             return result;
         }
         else{
             if (matches(_eLast)){
                 result.MoveTo(_eLast);
             }
         }
         
     }
 }
Exemple #25
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);
            }
        }
Exemple #26
0
        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;
                }
            }
        }
Exemple #27
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);
        }
Exemple #28
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("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.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)
                            {
                                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();
                    }
                }
            }
        }
Exemple #30
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);
        }
			public MSXslScript (XPathNavigator nav, Evidence evidence)
			{
				this.evidence = evidence;
				code = nav.Value;
				if (nav.MoveToFirstAttribute ()) {
					do {
						switch (nav.LocalName) {
						case "language":
							switch (nav.Value.ToLower (CultureInfo.InvariantCulture)) {
							case "jscript":
							case "javascript":
								language = ScriptingLanguage.JScript; break;
							case "vb":
							case "visualbasic":
								language = ScriptingLanguage.VisualBasic;
								break;
							case "c#":
							case "csharp":
								language = ScriptingLanguage.CSharp;
								break;
							default:
								throw new XsltException ("Invalid scripting language!", null);
							}
							break;
						case "implements-prefix":
							implementsPrefix = nav.Value;
							break;
						}
					} while (nav.MoveToNextAttribute ());
					nav.MoveToParent ();
				}
				
				if (implementsPrefix == null)
					throw new XsltException ("need implements-prefix attr", null);
			}
        /// <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;
        }
        public override string GetAttribute(string name)
        {
            string         str;
            string         str2;
            XPathNavigator nav = this.nav;

            switch (nav.NodeType)
            {
            case XPathNodeType.Element:
                break;

            case XPathNodeType.Attribute:
                nav = nav.Clone();
                if (nav.MoveToParent())
                {
                    break;
                }
                return(null);

            default:
                return(null);
            }
            ValidateNames.SplitQName(name, out str, out str2);
            if (str.Length == 0)
            {
                if (str2 == "xmlns")
                {
                    return(nav.GetNamespace(string.Empty));
                }
                if (nav == this.nav)
                {
                    nav = nav.Clone();
                }
                if (nav.MoveToAttribute(str2, string.Empty))
                {
                    return(nav.Value);
                }
            }
            else
            {
                if (str == "xmlns")
                {
                    return(nav.GetNamespace(str2));
                }
                if (nav == this.nav)
                {
                    nav = nav.Clone();
                }
                if (nav.MoveToFirstAttribute())
                {
                    do
                    {
                        if ((nav.LocalName == str2) && (nav.Prefix == str))
                        {
                            return(nav.Value);
                        }
                    }while (nav.MoveToNextAttribute());
                }
            }
            return(null);
        }
        public override bool MoveToNextAttribute()
        {
            switch (this.state)
            {
            case State.Content:
                return(this.MoveToFirstAttribute());

            case State.Attribute:
                if (XPathNodeType.Attribute != this.nav.NodeType)
                {
                    XPathNavigator other = this.nav.Clone();
                    if (other.MoveToParent())
                    {
                        if (!other.MoveToFirstNamespace(XPathNamespaceScope.Local))
                        {
                            return(false);
                        }
                        if (other.IsSamePosition(this.nav))
                        {
                            other.MoveToParent();
                            if (!other.MoveToFirstAttribute())
                            {
                                return(false);
                            }
                            this.nav.MoveTo(other);
                            return(true);
                        }
                        XPathNavigator navigator2 = other.Clone();
                        while (other.MoveToNextNamespace(XPathNamespaceScope.Local))
                        {
                            if (other.IsSamePosition(this.nav))
                            {
                                this.nav.MoveTo(navigator2);
                                return(true);
                            }
                            navigator2.MoveTo(other);
                        }
                    }
                    return(false);
                }
                return(this.nav.MoveToNextAttribute());

            case State.AttrVal:
                this.depth--;
                this.state = State.Attribute;
                if (this.MoveToNextAttribute())
                {
                    break;
                }
                this.depth++;
                this.state = State.AttrVal;
                return(false);

            case State.InReadBinary:
                this.state = this.savedState;
                if (this.MoveToNextAttribute())
                {
                    this.readBinaryHelper.Finish();
                    return(true);
                }
                this.state = State.InReadBinary;
                return(false);

            default:
                return(false);
            }
            this.nodeType = XmlNodeType.Attribute;
            return(true);
        }
        public override bool MoveToNextAttribute()
        {
            switch (this.state)
            {
            case State.Content:
                return(MoveToFirstAttribute());

            case State.Attribute: {
                if (XPathNodeType.Attribute == this.nav.NodeType)
                {
                    return(this.nav.MoveToNextAttribute());
                }

                // otherwise it is on a namespace... namespace are in reverse order
                Debug.Assert(XPathNodeType.Namespace == this.nav.NodeType);
                XPathNavigator nav = this.nav.Clone();
                if (!nav.MoveToParent())
                {
                    return(false);    // shouldn't happen
                }
                if (!nav.MoveToFirstNamespace(XPathNamespaceScope.Local))
                {
                    return(false);    // shouldn't happen
                }
                if (nav.IsSamePosition(this.nav))
                {
                    // this was the last one... start walking attributes
                    nav.MoveToParent();
                    if (!nav.MoveToFirstAttribute())
                    {
                        return(false);
                    }
                    // otherwise we are there
                    this.nav.MoveTo(nav);
                    return(true);
                }
                else
                {
                    XPathNavigator prev = nav.Clone();
                    for (;;)
                    {
                        if (!nav.MoveToNextNamespace(XPathNamespaceScope.Local))
                        {
                            Debug.Fail("Couldn't find Namespace Node! Should not happen!");
                            return(false);
                        }
                        if (nav.IsSamePosition(this.nav))
                        {
                            this.nav.MoveTo(prev);
                            return(true);
                        }
                        prev.MoveTo(nav);
                    }
                    // found previous namespace position
                }
            }

            case State.AttrVal:
                depth--;
                this.state = State.Attribute;
                if (!MoveToNextAttribute())
                {
                    depth++;
                    this.state = State.AttrVal;
                    return(false);
                }
                this.nodeType = XmlNodeType.Attribute;
                return(true);

            case State.InReadBinary:
                state = savedState;
                if (!MoveToNextAttribute())
                {
                    state = State.InReadBinary;
                    return(false);
                }
                readBinaryHelper.Finish();
                return(true);

            default:
                return(false);
            }
        }
        public override string GetAttribute(string name)
        {
            // reader allows calling GetAttribute, even when positioned inside attributes
            XPathNavigator nav = this.nav;

            switch (nav.NodeType)
            {
            case XPathNodeType.Element:
                break;

            case XPathNodeType.Attribute:
                nav = nav.Clone();
                if (!nav.MoveToParent())
                {
                    return(null);
                }
                break;

            default:
                return(null);
            }
            string prefix, localname;

            ValidateNames.SplitQName(name, out prefix, out localname);
            if (0 == prefix.Length)
            {
                if (localname == "xmlns")
                {
                    return(nav.GetNamespace(string.Empty));
                }
                if ((object)nav == (object)this.nav)
                {
                    nav = nav.Clone();
                }
                if (nav.MoveToAttribute(localname, string.Empty))
                {
                    return(nav.Value);
                }
            }
            else
            {
                if (prefix == "xmlns")
                {
                    return(nav.GetNamespace(localname));
                }
                if ((object)nav == (object)this.nav)
                {
                    nav = nav.Clone();
                }
                if (nav.MoveToFirstAttribute())
                {
                    do
                    {
                        if (nav.LocalName == localname && nav.Prefix == prefix)
                        {
                            return(nav.Value);
                        }
                    } while (nav.MoveToNextAttribute());
                }
            }
            return(null);
        }
 private bool moveToCount(XPathNavigator nav, Processor processor, XPathNavigator contextNode) {
     do {
         if (this.fromKey != Compiler.InvalidQueryKey && processor.Matches(nav, this.fromKey)) {
             return false;
         }
         if (MatchCountKey(processor, contextNode, nav)) {
             return true;
         }
     }while (nav.MoveToParent());
     return false;
 }
Exemple #38
0
        /// <summary>
        /// Initialize the ParentIterator.
        /// </summary>
        public void Create(XPathNavigator context, XmlNavigatorFilter filter)
        {
            // Save context node as current node
            _navCurrent = XmlQueryRuntime.SyncToNavigator(_navCurrent, context);

            // Attempt to find a matching parent node
            _haveCurrent = (_navCurrent.MoveToParent()) && (!filter.IsFiltered(_navCurrent));
        }
Exemple #39
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);
        }
		public virtual bool IsDescendant (XPathNavigator nav)
		{
			if (nav != null)
			{
				nav = nav.Clone ();
				while (nav.MoveToParent ())
				{
					if (IsSamePosition (nav))
						return true;
				}
			}
			return false;
		}
        /// <summary>
        /// Position "nav" to the matching node which follows it in document order but is not a descendant node.
        /// Return false if this is no such matching node.
        /// </summary>
        internal static bool MoveFirst(XmlNavigatorFilter filter, XPathNavigator nav) {
            // Attributes and namespace nodes include descendants of their owner element in the set of following nodes
            if (nav.NodeType == XPathNodeType.Attribute || nav.NodeType == XPathNodeType.Namespace) {
                if (!nav.MoveToParent()) {
                    // Floating attribute or namespace node that has no following nodes
                    return false;
                }

                if (!filter.MoveToFollowing(nav, null)) {
                    // No matching following nodes
                    return false;
                }
            }
            else {
                // XPath spec doesn't include descendants of the input node in the following axis
                if (!nav.MoveToNonDescendant())
                    // No following nodes
                    return false;

                // If the sibling does not match the node-test, find the next following node that does
                if (filter.IsFiltered(nav)) {
                    if (!filter.MoveToFollowing(nav, null)) {
                        // No matching following nodes
                        return false;
                    }
                }
            }

            // Success
            return true;
        }
		static IEnumerable EnumerateChildren (XPathNavigator n, string name, string ns)
		{
			if (!n.MoveToFirstChild ())
				yield break;
			n.MoveToParent ();
			XPathNavigator nav = n.Clone ();
			nav.MoveToFirstChild ();
			XPathNavigator nav2 = nav.Clone ();
			do {
				if ((name == String.Empty || nav.LocalName == name) && (ns == String.Empty || nav.NamespaceURI == ns)) {
					nav2.MoveTo (nav);
					yield return nav2;
				}
			} while (nav.MoveToNext ());
		}
 public override string GetAttribute( string name ) {
     // reader allows calling GetAttribute, even when positioned inside attributes
     XPathNavigator nav = this.nav;
     switch (nav.NodeType) {
         case XPathNodeType.Element:
             break;
         case XPathNodeType.Attribute:
             nav = nav.Clone();
             if (!nav.MoveToParent())
                 return null;
             break;
         default:
             return null;
     }
     string prefix, localname;
     ValidateNames.SplitQName( name, out prefix, out localname );
     if ( 0 == prefix.Length ) {
         if( localname == "xmlns" )
             return nav.GetNamespace( string.Empty );
         if ( (object)nav == (object)this.nav )
             nav = nav.Clone();
         if ( nav.MoveToAttribute( localname, string.Empty ) )
             return nav.Value;
     }
     else {
         if( prefix == "xmlns" )
             return nav.GetNamespace( localname );
         if ((object)nav == (object)this.nav)
             nav = nav.Clone();
         if (nav.MoveToFirstAttribute()) {
             do {
                 if (nav.LocalName == localname && nav.Prefix == prefix)
                     return nav.Value;
             } while (nav.MoveToNextAttribute());
         }
     }
     return null;
 }
Exemple #44
0
        public virtual bool Matches(XPathExpression expr)
        {
            Expression e = ((CompiledExpression)expr).ExpressionNode;

            if (e is ExprRoot)
            {
                return(NodeType == XPathNodeType.Root);
            }

            NodeTest nt = e as NodeTest;

            if (nt != null)
            {
                switch (nt.Axis.Axis)
                {
                case Axes.Child:
                case Axes.Attribute:
                    break;

                default:
                    throw new XPathException("Only child and attribute pattern are allowed for a pattern.");
                }
                return(nt.Match(((CompiledExpression)expr).NamespaceManager, this));
            }
            if (e is ExprFilter)
            {
                do
                {
                    e = ((ExprFilter)e).LeftHandSide;
                } while (e is ExprFilter);

                if (e is NodeTest && !((NodeTest)e).Match(((CompiledExpression)expr).NamespaceManager, this))
                {
                    return(false);
                }
            }

            XPathResultType resultType = e.ReturnType;

            switch (resultType)
            {
            case XPathResultType.Any:
            case XPathResultType.NodeSet:
                break;

            default:
                return(false);
            }

            switch (e.EvaluatedNodeType)
            {
            case XPathNodeType.Attribute:
            case XPathNodeType.Namespace:
                if (NodeType != e.EvaluatedNodeType)
                {
                    return(false);
                }
                break;
            }

            XPathNodeIterator nodes;

            nodes = this.Select(expr);
            while (nodes.MoveNext())
            {
                if (IsSamePosition(nodes.Current))
                {
                    return(true);
                }
            }

            // ancestors might select this node.

            XPathNavigator navigator = Clone();

            while (navigator.MoveToParent())
            {
                nodes = navigator.Select(expr);

                while (nodes.MoveNext())
                {
                    if (IsSamePosition(nodes.Current))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
		static IEnumerable EnumerateChildren (XPathNavigator n, XPathNodeType type)
		{
			if (!n.MoveToFirstChild ())
				yield break;
			n.MoveToParent ();
			XPathNavigator nav = n.Clone ();
			nav.MoveToFirstChild ();
			XPathNavigator nav2 = null;
			do {
				if (type == XPathNodeType.All || nav.NodeType == type) {
					if (nav2 == null)
						nav2 = nav.Clone ();
					else
						nav2.MoveTo (nav);
					yield return nav2;
				}
			} while (nav.MoveToNext ());
		}
 public override string GetAttribute( string localName, string namespaceURI ) {
     if ( null == localName )
         throw new ArgumentNullException("localName");
     // reader allows calling GetAttribute, even when positioned inside attributes
     XPathNavigator nav = this.nav;
     switch (nav.NodeType) {
         case XPathNodeType.Element:
             break;
         case XPathNodeType.Attribute:
             nav = nav.Clone();
             if (!nav.MoveToParent())
                 return null;
             break;
         default:
             return null;
     }
     // are they really looking for a namespace-decl?
     if( namespaceURI == XmlReservedNs.NsXmlNs ) {
         if (localName == "xmlns")
             localName = string.Empty;
         return nav.GetNamespace( localName );
     }
     if ( null == namespaceURI )
         namespaceURI = string.Empty;
     // We need to clone the navigator and move the clone to the attribute to see whether the attribute exists, 
     // because XPathNavigator.GetAttribute return string.Empty for both when the the attribute is not there or when 
     // it has an empty value. XmlReader.GetAttribute must return null if the attribute does not exist.
     if ((object)nav == (object)this.nav)
         nav = nav.Clone();
     if ( nav.MoveToAttribute( localName, namespaceURI ) ) {
         return nav.Value;
     }
     else {
         return null;
     }
 }
 // check 'from' condition:
 // if 'from' exist it has to be ancestor-or-self for the nav
 private bool checkFrom(Processor processor, XPathNavigator nav) {
     if(this.fromKey == Compiler.InvalidQueryKey) {
         return true;
     }
     do {
         if (processor.Matches(nav, this.fromKey)) {
             return true;
         }
     }while (nav.MoveToParent());
     return false;
 }
Exemple #48
0
        public 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);
        }
Exemple #49
0
		public void Fill (XPathNavigator nav)
		{
			if (nav.MoveToFirstAttribute ()) {
				ProcessAttribute (nav);
				while (nav.MoveToNextAttribute ()) {
					ProcessAttribute (nav);
				}

				// move back to original position
				nav.MoveToParent ();
			}
		}
        /// <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);
        }