MoveToFirstAttribute() public abstract method

public abstract MoveToFirstAttribute ( ) : bool
return bool
Example #1
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();
            }

        }
			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);
			}
Example #3
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();
             }
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of an XmlNodeTaskItem
        /// </summary>
        /// <param name="xpathNavigator">The selected XmlNode</param>
        /// <param name="reservedMetaDataPrefix">The prefix to attach to the reserved metadata properties.</param>
        public XmlNodeTaskItem(XPathNavigator xpathNavigator, string reservedMetaDataPrefix)
        {
            this.ReservedMetaDataPrefix = reservedMetaDataPrefix;

            switch (xpathNavigator.NodeType)
            {
                case XPathNodeType.Attribute:
                    itemSpec = xpathNavigator.Value;
                    break;
                default:
                    itemSpec = xpathNavigator.Name;
                    break;
            }
            metaData.Add(ReservedMetaDataPrefix + "value", xpathNavigator.Value);
            metaData.Add(ReservedMetaDataPrefix + "innerXml", xpathNavigator.InnerXml);
            metaData.Add(ReservedMetaDataPrefix + "outerXml", xpathNavigator.OuterXml);

            if (xpathNavigator.MoveToFirstAttribute())
            {
                do
                {
                    metaData.Add(xpathNavigator.Name, xpathNavigator.Value);
                } while (xpathNavigator.MoveToNextAttribute());
            }
        }
		private void Parse(XPathNavigator classCacheElement)
		{
			if (classCacheElement.MoveToFirstAttribute())
			{
				do
				{
					switch (classCacheElement.Name)
					{
						case "class":
							if (classCacheElement.Value.Trim().Length == 0)
								throw new HibernateConfigException("Invalid class-cache element; the attribute <class> must be assigned with no empty value");
							clazz = classCacheElement.Value;
							break;
						case "usage":
							usage = EntityCacheUsageParser.Parse(classCacheElement.Value);
							break;
						case "region":
							region = classCacheElement.Value;
							break;
						case "include":
							include = CfgXmlHelper.ClassCacheIncludeConvertFrom(classCacheElement.Value);
							break;
					}
				}
				while (classCacheElement.MoveToNextAttribute());
			}			
		}
Example #6
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();
            }
             }
        }
		private void Parse(XPathNavigator eventElement)
		{
			XPathNavigator eventClone = eventElement.Clone();
			eventElement.MoveToFirstAttribute();
			type = CfgXmlHelper.ListenerTypeConvertFrom(eventElement.Value);
			XPathNodeIterator listenersI = eventClone.SelectDescendants(XPathNodeType.Element, false);
			while (listenersI.MoveNext())
			{
				listeners.Add(new ListenerConfiguration(listenersI.Current, type));
			}
		}
Example #8
0
 string GetAssemblyVersion(XPathNavigator nav)
 {
     if(nav.HasAttributes)
         nav.MoveToFirstAttribute();
     do
     {
         if (Utilities.Compare(nav.LocalName, "version"))
             return nav.Value;
     } while (nav.MoveToNextAttribute( ));
     return string.Empty;
 }
Example #9
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;
 }
Example #10
0
		public SettingsMappingWhatContents (XPathNavigator nav, SettingsMappingWhatOperation operation)
		{
			_operation = operation;
      
			if (nav.HasAttributes) {	
				nav.MoveToFirstAttribute ();
				_attributes.Add (nav.Name, nav.Value);
	
				while (nav.MoveToNextAttribute ())
					_attributes.Add (nav.Name, nav.Value);
			}
		}
Example #11
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();
         }
      }
        private static void WriteAttributes(TextWriter writer, XPathNavigator nav, string leadIn)
        {
            nav.MoveToFirstAttribute();

            do
            {
                writer.Write(leadIn);
                writer.Write(nav.Name);
                writer.Write(Constants.Space);
                writer.WriteLine(nav.Value);
            } while (nav.MoveToNextAttribute());

            nav.MoveToParent();
        }
Example #13
0
        /// <summary>
        /// Parses the "version" node represented by a <see cref="XPathNavigator"/> object.
        /// </summary>
        /// <param name="xpathNav">The <see cref="XPathNavigator"/> object containing the "version" node.</param>
        /// <returns>An instance of the <see cref="AppVersionInfo"/> class.</returns>
        /// <exception cref="VersionCheckingException"></exception>
        private static AppVersionInfo ParseAppTag(XPathNavigator xpathNav)
        {
            string name = null;
            Version version = null;
            string informationalVersion = null;
            string description = null;
            string downloadUrl = null;

            if (xpathNav.MoveToFirstAttribute())
            {
                do
                {
                    switch (xpathNav.Name)
                    {
                        case "name":
                            name = xpathNav.Value;
                            break;

                        case "version":
                            try
                            {
                                version = new Version(xpathNav.Value);
                            }
                            catch (Exception ex)
                            {
                                throw new VersionCheckingException(VersioningResources.Error_VersionInformation_InvalidVersionsFile_InvalidVersionAttribute, ex);
                            }
                            break;

                        case "informationalVersion":
                            informationalVersion = xpathNav.Value;
                            break;

                        case "description":
                            description = xpathNav.Value;
                            break;

                        case "downloadUrl":
                            downloadUrl = xpathNav.Value;
                            break;
                    }
                } while (xpathNav.MoveToNextAttribute());
            }

            if (version == null)
                throw new VersionCheckingException(VersioningResources.Error_VersionInformation_VersionAttributeNotFound);

            return new AppVersionInfo(name, version, informationalVersion, description, downloadUrl);
        }
 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();
     }
 }
Example #15
0
File: Debug.cs Project: nobled/mono
		internal static void TraceContext(XPathNavigator context) {
			string output = "(null)";
			
			if (context != null) {
				context = context.Clone ();
				switch (context.NodeType) {
					case XPathNodeType.Element:
						output = string.Format("<{0}:{1}", context.Prefix, context.LocalName);
						for (bool attr = context.MoveToFirstAttribute(); attr; attr = context.MoveToNextAttribute()) {
							output += string.Format(CultureInfo.InvariantCulture, " {0}:{1}={2}", context.Prefix, context.LocalName, context.Value);
						}
						 output += ">";
						break;
					default:
						break;
				}
			}
	
			WriteLine(output);
		}
Example #16
0
		private void Parse(XPathNavigator listenerElement)
		{
			if (listenerElement.MoveToFirstAttribute())
			{
				do
				{
					switch (listenerElement.Name)
					{
						case "class":
							if (listenerElement.Value.Trim().Length == 0)
								throw new HibernateConfigException("Invalid listener element; the attribute <class> must be assigned with no empty value");
							clazz = listenerElement.Value;
							break;
						case "type":
							type = CfgXmlHelper.ListenerTypeConvertFrom(listenerElement.Value);
							break;
					}
				}
				while (listenerElement.MoveToNextAttribute());
			}
		}
		private void Parse(XPathNavigator collectionCacheElement)
		{
			if (collectionCacheElement.MoveToFirstAttribute())
			{
				do
				{
					switch (collectionCacheElement.Name)
					{
						case "collection":
							if (collectionCacheElement.Value.Trim().Length == 0)
								throw new HibernateConfigException("Invalid collection-cache element; the attribute <collection> must be assigned with no empty value");
							collection = collectionCacheElement.Value;
							break;
						case "usage":
							usage = EntityCacheUsageParser.Parse(collectionCacheElement.Value);
							break;
						case "region":
							region = collectionCacheElement.Value;
							break;
					}
				}
				while (collectionCacheElement.MoveToNextAttribute());
			}
		}
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component">The XPath navigator containing the
        /// component's configuration information</param>
        internal BuildComponentInfo(XPathNavigator component)
        {
            StringBuilder sb = new StringBuilder();
            FileVersionInfo fvi;
            XPathNavigator item;
            string asmPath, attrValue;

            isValid = true;

            // Load the configuration information from the node
            try
            {
                attrValue = component.GetAttribute("type", String.Empty);

                if(String.IsNullOrEmpty(attrValue))
                {
                    isValid = false;
                    typeName = "??";
                    invalidReason = "Missing type name attribute";
                }
                else
                    typeName = attrValue;

                // If no ID, use the type name
                attrValue = component.GetAttribute("id", String.Empty);

                if(!String.IsNullOrEmpty(attrValue))
                    id = attrValue;
                else
                    id = typeName;

                attrValue = component.GetAttribute("assembly", String.Empty);

                if(String.IsNullOrEmpty(attrValue))
                {
                    isValid = false;
                    assemblyPath = "??";
                    invalidReason = "Missing assembly attribute";
                }
                else
                {
                    assemblyPath = attrValue;

                    // Try to get copyright and version information
                    asmPath = BuildComponentManager.ResolveComponentPath(
                        assemblyPath);

                    if(File.Exists(asmPath))
                    {
                        fvi = FileVersionInfo.GetVersionInfo(asmPath);
                        version = new Version(fvi.FileVersion);
                        copyright = fvi.LegalCopyright;
                    }
                    else
                    {
                        version = new Version("0.0.0.0");
                        copyright = "?? - Unable to locate assembly";
                        isValid = false;
                        invalidReason = "The build component assembly " +
                            asmPath + " could not be found";
                    }
                }

                // If no description use the type name and assembly path
                item = component.SelectSingleNode("description");
                if(item != null)
                    description = item.Value.Trim();
                else
                    description = typeName + ", " + assemblyPath;

                if(component.SelectSingleNode("hidden") != null)
                    isHidden = true;

                item = component.SelectSingleNode("configureMethod");
                if(item != null)
                {
                    attrValue = item.GetAttribute("name", String.Empty);

                    if(!String.IsNullOrEmpty(attrValue))
                        configureMethod = attrValue;
                }

                // The default configuration is wrapped in a <component> tag
                item = component.SelectSingleNode("defaultConfiguration");

                // We need to retain custom attributes on the component as well
                // as the standard id, type, and assembly attributes.
                sb.Append("<component");

                if(component.MoveToFirstAttribute())
                {
                    do
                    {
                        sb.AppendFormat(" {0}=\"{1}\"", component.Name,
                            component.Value);
                    } while(component.MoveToNextAttribute());

                    component.MoveToParent();
                }

                sb.AppendFormat(CultureInfo.InvariantCulture,
                    ">\r\n{0}\r\n</component>",
                    (item == null) ? String.Empty : item.InnerXml);

                defaultConfig = sb.ToString();

                item = component.SelectSingleNode("insert");
                if(item != null)
                    referencePosition = new ComponentPosition(item);
                else
                    referencePosition = new ComponentPosition();

                item = component.SelectSingleNode("insertConceptual");
                if(item != null)
                    conceptualPosition = new ComponentPosition(item);
                else
                    conceptualPosition = new ComponentPosition();

                List<string> deps = new List<string>();

                foreach(XPathNavigator dep in component.Select(
                  "dependencies/component"))
                {
                    attrValue = dep.GetAttribute("id", String.Empty);
                    if(!String.IsNullOrEmpty(attrValue))
                        deps.Add(attrValue);
                }

                dependencies = new ReadOnlyCollection<string>(deps);
            }
            catch(Exception ex)
            {
                isValid = false;
                invalidReason = ex.Message;
            }
        }
        /// <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);
                }
            }
        }
Example #20
0
		public void AttributeNavigation ()
		{
			document.LoadXml ("<foo bar='baz' quux='quuux' />");
			navigator = document.DocumentElement.CreateNavigator ();

			Assert.AreEqual (XPathNodeType.Element, navigator.NodeType, "#1");
			Assert.AreEqual ("foo", navigator.Name, "#2");
			Assert.IsTrue (navigator.MoveToFirstAttribute (), "#3");
			Assert.AreEqual (XPathNodeType.Attribute, navigator.NodeType, "#4");
			Assert.AreEqual ("bar", navigator.Name, "#5");
			Assert.AreEqual ("baz", navigator.Value, "#6");
			Assert.IsTrue (navigator.MoveToNextAttribute (), "#7");
			Assert.AreEqual (XPathNodeType.Attribute, navigator.NodeType, "#8");
			Assert.AreEqual ("quux", navigator.Name, "#9");
			Assert.AreEqual ("quuux", navigator.Value, "#10");
		}
Example #21
0
 /// <summary>
 /// If navigator is positioned on an attribute, move to the next attribute node.  If there are no more
 /// attributes, move to the first content node.  If navigator is positioned on a content node, move to
 /// the next content node.  If there are no more attributes and content nodes, return null.
 /// Otherwise, return navigator.
 /// </summary>
 public static bool MoveToNextAttributeContent(XPathNavigator navigator) {
     if (navigator.NodeType == XPathNodeType.Attribute) {
         if (!navigator.MoveToNextAttribute()) {
             navigator.MoveToParent();
             if (!navigator.MoveToFirstChild()) {
                 // No children, so reposition on original attribute
                 navigator.MoveToFirstAttribute();
                 while (navigator.MoveToNextAttribute())
                     ;
                 return false;
             }
         }
         return true;
     }
     return navigator.MoveToNext();
 }
Example #22
0
 /// <summary>
 /// Move to navigator's first attribute node.  If no attribute's exist, move to the first content node.
 /// If no content nodes exist, return null.  Otherwise, return navigator.
 /// </summary>
 public static bool MoveToFirstAttributeContent(XPathNavigator navigator) {
     if (!navigator.MoveToFirstAttribute())
         return navigator.MoveToFirstChild();
     return true;
 }
        public override bool MoveToAttribute(string name)
        {
            int            depth;
            XPathNavigator nav = GetElemNav(out depth);

            if (null == nav)
            {
                return(false);
            }

            string prefix, localname;

            ValidateNames.SplitQName(name, out prefix, out localname);

            // watch for a namespace name
            bool IsXmlnsNoPrefix = false;

            if ((IsXmlnsNoPrefix = (0 == prefix.Length && localname == "xmlns")) ||
                (prefix == "xmlns"))
            {
                if (IsXmlnsNoPrefix)
                {
                    localname = string.Empty;
                }
                if (nav.MoveToFirstNamespace(XPathNamespaceScope.Local))
                {
                    do
                    {
                        if (nav.LocalName == localname)
                        {
                            goto FoundMatch;
                        }
                    } while (nav.MoveToNextNamespace(XPathNamespaceScope.Local));
                }
            }
            else if (0 == prefix.Length)
            {
                // the empty prefix always means empty namespaceUri for attributes
                if (nav.MoveToAttribute(localname, string.Empty))
                {
                    goto FoundMatch;
                }
            }
            else
            {
                if (nav.MoveToFirstAttribute())
                {
                    do
                    {
                        if (nav.LocalName == localname && nav.Prefix == prefix)
                        {
                            goto FoundMatch;
                        }
                    } while (nav.MoveToNextAttribute());
                }
            }
            return(false);

FoundMatch:
            if (_state == State.InReadBinary)
            {
                _readBinaryHelper.Finish();
                _state = _savedState;
            }
            MoveToAttr(nav, depth + 1);
            return(true);
        }
Example #24
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 #25
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 override string GetAttribute(string name)
        {
            // reader allows calling GetAttribute, even when positioned inside attributes
            XPathNavigator nav = _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)_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)_nav)
                {
                    nav = nav.Clone();
                }
                if (nav.MoveToFirstAttribute())
                {
                    do
                    {
                        if (nav.LocalName == localname && nav.Prefix == prefix)
                        {
                            return(nav.Value);
                        }
                    } while (nav.MoveToNextAttribute());
                }
            }
            return(null);
        }
        public override bool MoveToAttribute(string name)
        {
            int            num;
            string         str;
            string         str2;
            XPathNavigator elemNav = this.GetElemNav(out num);

            if (elemNav == null)
            {
                return(false);
            }
            ValidateNames.SplitQName(name, out str, out str2);
            bool flag = false;

            if ((flag = (str.Length == 0) && (str2 == "xmlns")) || (str == "xmlns"))
            {
                if (flag)
                {
                    str2 = string.Empty;
                }
                if (elemNav.MoveToFirstNamespace(XPathNamespaceScope.Local))
                {
                    do
                    {
                        if (elemNav.LocalName == str2)
                        {
                            goto Label_00B5;
                        }
                    }while (elemNav.MoveToNextNamespace(XPathNamespaceScope.Local));
                }
            }
            else
            {
                if (str.Length == 0)
                {
                    if (!elemNav.MoveToAttribute(str2, string.Empty))
                    {
                        goto Label_00B3;
                    }
                    goto Label_00B5;
                }
                if (elemNav.MoveToFirstAttribute())
                {
                    do
                    {
                        if ((elemNav.LocalName == str2) && (elemNav.Prefix == str))
                        {
                            goto Label_00B5;
                        }
                    }while (elemNav.MoveToNextAttribute());
                }
            }
Label_00B3:
            return(false);

Label_00B5:
            if (this.state == State.InReadBinary)
            {
                this.readBinaryHelper.Finish();
                this.state = this.savedState;
            }
            this.MoveToAttr(elemNav, num + 1);
            return(true);
        }
        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);
        }
Example #29
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);
                }
            }
        }
        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);
        }
		private void IsDescendant (XPathNavigator nav)
		{
			XPathNavigator tmp = nav.Clone ();
			XPathNodeIterator iter = nav.Select ("//e");
			iter.MoveNext ();
			Assert.IsTrue (nav.MoveTo (iter.Current), "#1");
			Assert.IsTrue (nav.MoveToFirstAttribute (), "#2");
			Assert.AreEqual ("attr", nav.Name, "#3");
			Assert.AreEqual ("", tmp.Name, "#4");
			Assert.IsTrue (tmp.IsDescendant (nav), "#5");
			Assert.IsTrue (!nav.IsDescendant (tmp), "#6");
			tmp.MoveToFirstChild ();
			Assert.AreEqual ("a", tmp.Name, "#7");
			Assert.IsTrue (tmp.IsDescendant (nav), "#8");
			Assert.IsTrue (!nav.IsDescendant (tmp), "#9");
			tmp.MoveTo (iter.Current);
			Assert.AreEqual ("e", tmp.Name, "#10");
			Assert.IsTrue (tmp.IsDescendant (nav), "#11");
			Assert.IsTrue (!nav.IsDescendant (tmp), "#12");
		}
Example #32
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);
        }
Example #33
0
      public void ReadXml(XPathNavigator node) {

         bool movedToDocEl = false;

         if (node.NodeType == XPathNodeType.Root)
            movedToDocEl = node.MoveToChild(XPathNodeType.Element);

         if (node.NamespaceURI == XPathSmtpClient.Namespace
            && node.LocalName == "message") {

            if (node.MoveToFirstAttribute()) {

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

                  }
               } while (node.MoveToNextAttribute());

               node.MoveToParent();
            }

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

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

                     switch (node.LocalName) {
                        case "from":
                           this.From = new XPathMailAddress();
                           this.From.ReadXml(node);
                           break;

                        case "reply-to": {
                              XPathMailAddress address = new XPathMailAddress();
                              address.ReadXml(node);

                              this.ReplyTo.Add(address);
                           }
                           break;

                        case "sender":
                           this.Sender = new XPathMailAddress();
                           this.Sender.ReadXml(node);
                           break;

                        case "to": {
                              XPathMailAddress address = new XPathMailAddress();
                              address.ReadXml(node);

                              this.To.Add(address);
                           }
                           break;

                        case "cc": {
                              XPathMailAddress address = new XPathMailAddress();
                              address.ReadXml(node);

                              this.CC.Add(address);
                           }
                           break;

                        case "bcc": {
                              XPathMailAddress address = new XPathMailAddress();
                              address.ReadXml(node);

                              this.Bcc.Add(address);
                           }
                           break;

                        case "subject":
                           this.Subject = node.Value;
                           break;

                        case "body":
                           this.Body = new XPathMailBody();
                           this.Body.ReadXml(node);
                           break;

                        default:
                           break;
                     }
                  }

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

               node.MoveToParent();
            }
         }

         if (movedToDocEl)
            node.MoveToParent();
      }
		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);
		}
Example #35
0
        public void ReadXml(XPathNavigator node)
        {
            bool movedToDocEl = false;

             if (node.NodeType == XPathNodeType.Root) {
            movedToDocEl = node.MoveToChild(XPathNodeType.Element);
             }

             if (node.NamespaceURI == XPathHttpClient.Namespace
            && node.LocalName == "request") {

            if (node.NodeType == XPathNodeType.Element) {

               if (node.MoveToFirstAttribute()) {

                  do {
                     switch (node.LocalName) {
                        case "method":
                           this.Method = node.Value;
                           break;

                        case "href":
                           this.Href = new Uri(node.Value, UriKind.Absolute);
                           break;

                        case "status-only":
                           this.StatusOnly = node.ValueAsBoolean;
                           break;

                        case "username":
                           this.Username = node.Value;
                           break;

                        case "password":
                           this.Password = node.Value;
                           break;

                        case "auth-method":
                           this.AuthMethod = node.Value;
                           break;

                        case "send-authorization":
                           this.SendAuthorization = node.ValueAsBoolean;
                           break;

                        case "override-media-type":
                           this.OverrideMediaType = node.Value;
                           break;

                        case "follow-redirect":
                           this.FollowRedirect = node.ValueAsBoolean;
                           break;

                        case "timeout":
                           this.Timeout = node.ValueAsInt;
                           break;

                        default:
                           break;
                     }

                  } while (node.MoveToNextAttribute());

                  node.MoveToParent();
               }

               if (node.MoveToChild(XPathNodeType.Element)) {
                  do {
                     if (node.NamespaceURI == XPathHttpClient.Namespace) {
                        switch (node.LocalName) {
                           case "header":
                              this.Headers.Add(node.GetAttribute("name", ""), node.GetAttribute("value", ""));
                              break;

                           case "body":
                              this.Body = new XPathHttpBody();
                              this.Body.ReadXml(node, this.Resolver);
                              break;

                           case "multipart":
                              this.Multipart = new XPathHttpMultipart();
                              this.Multipart.ReadXml(node, this.Resolver);
                              break;

                           default:
                              break;
                        }
                     }
                  } while (node.MoveToNext(XPathNodeType.Element));

                  node.MoveToParent();
               }
            }
             }

             if (movedToDocEl) {
            node.MoveToParent();
             }
        }
Example #36
0
        /// <summary>
        /// Function analyzes children of the node recursively
        /// </summary>
        /// <param name="nodeNavigator">current node whose children schould be analyzed</param>
        /// <param name="groupName">currently created sequence of group names to this node</param>
        /// <param name="parameterName">name of the compared parameter</param>
        /// <param name="dictionaryEntry">entry for currently analyzed xml doc</param>
        /// <param name="temp">temporary entry for the parameter to be filled</param>
        public void AnalyzeNodeChildren(XPathNavigator nodeNavigator, string groupName, string parameterName, KeyValuePair<string, XPathDocument> dictionaryEntry, Dictionary<ParameterID, Dictionary<String, object>> temp)
        {
            nodeNavigator.MoveToFirstChild();

            do
            {
                //----comparing param's attributes-----------------

                if (nodeNavigator.HasChildren)
                {
                    // This is a group
                    StringBuilder groupNameNewSB = new StringBuilder();
                    nodeNavigator.MoveToAttribute("NAME", "");

                    groupNameNewSB.Append(groupName);
                    if (groupName != "")
                    {
                        groupNameNewSB.Append(".");
                    }

                    groupNameNewSB.Append(nodeNavigator.Value);

                    nodeNavigator.MoveToParent();
                    AnalyzeNodeChildren(nodeNavigator, groupNameNewSB.ToString(), parameterName, dictionaryEntry, temp);
                }
                else
                {
                    nodeNavigator.MoveToFirstAttribute();

                    do
                    {
                        switch (nodeNavigator.Name)
                        {
                            case "NAME":
                                break;
                            case "HINT":
                                break;
                            case "TYPE":
                                break;
                            case "VALUE": // this can be done better....... but anyways , let's continue :)
                                //paramValue = Convert.ToDouble(thisNavigator.ValueAsDouble);
                                object paramValue = null;
                                double doubleValue;
                                bool paramIsString = false;
                                if (!Double.TryParse(nodeNavigator.Value, NumberStyles.Number, CultureInfo.InvariantCulture/*CultureInfo.CreateSpecificCulture("en-GB")*/, out doubleValue))
                                {
                                    paramValue = nodeNavigator.Value;
                                    paramIsString = true;
                                }

                                //------- move to attribute doesn't work backwards (no idea why)
                                // update: because it cannot go from attribute to attribute with the use of
                                //MoveToAttribute method (in this case only MoveToNextAttribute can be used)
                                nodeNavigator.MoveToParent();
                                nodeNavigator.MoveToFirstChild();
                                nodeNavigator.MoveToAttribute("NAME", "");

                                //if no match with desired name 'break;' and go to the next one
                                if (!nodeNavigator.Value.Contains(parameterName))
                                {
                                    nodeNavigator.MoveToParent();
                                    nodeNavigator.MoveToFirstChild();
                                    nodeNavigator.MoveToAttribute("VALUE", "");
                                    break;
                                }

                                #region Adding parameter to temp
                                //....add( (fileName, Concatenated String <groupName + , +  parameterName>), parameterValue)
                                if (paramIsString)
                                {
                                    // For this I could have written a function :)
                                    Dictionary<string, object> tempDictionary = new Dictionary<string, object>();

                                    ///if this parameter entry already exists, then only add it's difference entry in its dictionary
                                    if (temp.TryGetValue(new ParameterID(nodeNavigator.Value, groupName, true), out tempDictionary))
                                    //if (temp.ContainsKey(new parameterID(thisNavigator.Value, groupName)))
                                    {
                                        tempDictionary.Add(dictionaryEntry.Key, paramValue);
                                    }
                                    else
                                    {
                                        tempDictionary = new Dictionary<string, object>();
                                        tempDictionary.Add(dictionaryEntry.Key, paramValue);
                                        temp.Add(new ParameterID(nodeNavigator.Value, groupName, true), tempDictionary);
                                        //(DictionaryEntry.Key, groupName + ", " + thisNavigator.Value), paramValue);
                                    }
                                }
                                else
                                {
                                    Dictionary<string, object> tempDictionary = new Dictionary<string, object>();

                                    ///if this parameter entry already exists, then only add it's difference entry in its dictionary
                                    if (temp.TryGetValue(new ParameterID(nodeNavigator.Value, groupName, false), out tempDictionary))
                                    //if (temp.ContainsKey(new parameterID(thisNavigator.Value, groupName)))
                                    {
                                        tempDictionary.Add(dictionaryEntry.Key, doubleValue);
                                    }
                                    else
                                    {
                                        tempDictionary = new Dictionary<string, object>();
                                        tempDictionary.Add(dictionaryEntry.Key, doubleValue);
                                        temp.Add(new ParameterID(nodeNavigator.Value, groupName, false), tempDictionary);
                                        //(DictionaryEntry.Key, groupName + ", " + thisNavigator.Value), paramValue);
                                    }
                                }
                                #endregion

                                //again - doesn't work backwards
                                nodeNavigator.MoveToParent();
                                nodeNavigator.MoveToFirstChild();
                                nodeNavigator.MoveToAttribute("VALUE", "");

                                break;
                            case "LEVEL":
                                break;
                            default:
                                break;
                        }

                    } while (nodeNavigator.MoveToNextAttribute());
                    nodeNavigator.MoveToParent();
                }
            } while (nodeNavigator.MoveToNext());//iteration on params

            nodeNavigator.MoveToParent();
        }
        public override bool MoveToNextAttribute()
        {
            switch (_state)
            {
            case State.Content:
                return(MoveToFirstAttribute());

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

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

            case State.AttrVal:
                _depth--;
                _state = State.Attribute;
                if (!MoveToNextAttribute())
                {
                    _depth++;
                    _state = State.AttrVal;
                    return(false);
                }
                _nodeType = XmlNodeType.Attribute;
                return(true);

            case State.InReadBinary:
                _state = _savedState;
                if (!MoveToNextAttribute())
                {
                    _state = State.InReadBinary;
                    return(false);
                }
                _readBinaryHelper.Finish();
                return(true);

            default:
                return(false);
            }
        }
Example #38
0
		public void Fill (XPathNavigator nav)
		{
			if (nav.MoveToFirstAttribute ()) {
				ProcessAttribute (nav);
				while (nav.MoveToNextAttribute ()) {
					ProcessAttribute (nav);
				}

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