예제 #1
0
 /// <summary>
 ///   Adds the contents of another <see cref='QualifiedNameCollection'/> to the end of the collection.
 /// </summary>
 /// <param name='val'>
 ///    A <see cref='QualifiedNameCollection'/> containing the objects to add to the collection.
 /// </param>
 /// <seealso cref='QualifiedNameCollection.Add'/>
 public void AddRange(QualifiedNameCollection val)
 {
     for (int i = 0; i < val.Count; i++)
     {
         this.Add(val[i]);
     }
 }
 public void AddRange(QualifiedNameCollection names)
 {
     for (int i = 0; i < names.Count; i++)
     {
         Add(names[i]);
     }
 }
예제 #3
0
        /// <summary>
        /// Gets the parent element path based on the index position.
        /// </summary>
        public static XmlElementPath GetParentElementPath(string xml)
        {
            QualifiedNameCollection namespaces = new QualifiedNameCollection();
            XmlElementPath          path       = GetFullParentElementPath(xml, namespaces);

            path.Compact();
            return(path);
        }
        public void CreateQualifiedNameCollectionInstanceUsingQualifiedNameCollection()
        {
            QualifiedName[] array = new QualifiedName[] { firstName, secondName };
            QualifiedNameCollection oldCollection = new QualifiedNameCollection(array);
            QualifiedNameCollection newCollection = new QualifiedNameCollection(oldCollection);

            Assert.AreSame(firstName, newCollection[0]);
        }
		public void Init()
		{
			firstName = new QualifiedName("first", "first-ns", "first-prefix");
			secondName = new QualifiedName("second", "second-ns", "second-prefix");	
			
			QualifiedName[] array = new QualifiedName[] { firstName, secondName };
			qualifiedNameCollection = new QualifiedNameCollection(array);
		}
예제 #6
0
 /// <summary>
 /// Finds the namespace for the specified prefix.
 /// </summary>
 static string GetNamespaceForPrefix(QualifiedNameCollection namespaces, string prefix)
 {
     foreach (QualifiedName name in namespaces)
     {
         if (name.Prefix == prefix)
         {
             return(name.Namespace);
         }
     }
     return(String.Empty);
 }
예제 #7
0
        /// <summary>
        /// Gets path of the xml element start tag that the specified
        /// <paramref name="index"/> is currently inside.
        /// </summary>
        /// <remarks>If the index outside the start tag then an empty path
        /// is returned.</remarks>
        /// <param name="namespaces">Returns the namespaces that are
        /// exist in the xml.</param>
        static XmlElementPath GetActiveElementStartPath(string xml, int index, QualifiedNameCollection namespaces)
        {
            XmlElementPath path        = new XmlElementPath();
            string         elementText = GetActiveElementStartText(xml, index);

            if (elementText != null)
            {
                path = GetActiveElementStartPath(xml, index, elementText, namespaces);
            }
            return(path);
        }
예제 #8
0
        /// <summary>
        /// Gets the name of the attribute and its prefix at the specified index. The index
        /// can be anywhere inside the attribute name or in the attribute value.
        /// The namespace for the element containing the attribute will also be determined
        /// if the includeNamespace flag is set to true.
        /// </summary>
        public static QualifiedName GetQualifiedAttributeNameAtIndex(string xml, int index, bool includeNamespace)
        {
            string        name          = GetAttributeNameAtIndex(xml, index);
            QualifiedName qualifiedName = GetQualifiedName(name);

            if (qualifiedName != null && String.IsNullOrEmpty(qualifiedName.Namespace) && includeNamespace)
            {
                QualifiedNameCollection namespaces = new QualifiedNameCollection();
                XmlElementPath          path       = GetActiveElementStartPathAtIndex(xml, index, namespaces);
                qualifiedName.Namespace = GetNamespaceForPrefix(namespaces, path.Elements.LastPrefix);
            }
            return(qualifiedName);
        }
예제 #9
0
        /// <summary>
        /// Gets the parent element path based on the index position. This
        /// method does not compact the path so it will include all elements
        /// including those in another namespace in the path.
        /// </summary>
        static XmlElementPath GetFullParentElementPath(string xml, QualifiedNameCollection namespaces)
        {
            XmlElementPath path = new XmlElementPath();
            IDictionary <string, string> namespacesInScope = null;

            using (StringReader reader = new StringReader(xml)) {
                using (XmlTextReader xmlReader = new XmlTextReader(reader)) {
                    try {
                        xmlReader.XmlResolver = null;                         // prevent XmlTextReader from loading external DTDs
                        while (xmlReader.Read())
                        {
                            switch (xmlReader.NodeType)
                            {
                            case XmlNodeType.Element:
                                if (!xmlReader.IsEmptyElement)
                                {
                                    QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix);
                                    path.Elements.Add(elementName);
                                }
                                break;

                            case XmlNodeType.EndElement:
                                path.Elements.RemoveLast();
                                break;
                            }
                        }
                    } catch (XmlException) {
                        namespacesInScope = xmlReader.GetNamespacesInScope(XmlNamespaceScope.All);
                    }
                }
            }

            // Add namespaces in scope for the last element read.
            if (namespacesInScope != null)
            {
                foreach (KeyValuePair <string, string> ns in namespacesInScope)
                {
                    namespaces.Add(new QualifiedName(String.Empty, ns.Value, ns.Key));
                }
            }

            return(path);
        }
예제 #10
0
        public override bool Equals(object obj)
        {
            QualifiedNameCollection rhs = obj as QualifiedNameCollection;

            if (rhs != null)
            {
                if (Count == rhs.Count)
                {
                    for (int i = 0; i < Count; ++i)
                    {
                        QualifiedName lhsName = this[i];
                        QualifiedName rhsName = rhs[i];
                        if (!lhsName.Equals(rhsName))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
예제 #11
0
		/// <summary>
		/// Gets path of the xml element start tag that the specified
		/// <paramref name="index"/> is currently located. This is different to the
		/// GetActiveElementStartPath method since the index can be inside the element
		/// name.
		/// </summary>
		/// <remarks>If the index outside the start tag then an empty path
		/// is returned.</remarks>
		public static XmlElementPath GetActiveElementStartPathAtIndex(string xml, int index)
		{
			QualifiedNameCollection namespaces = new QualifiedNameCollection();
			return GetActiveElementStartPathAtIndex(xml, index, namespaces);
		}
예제 #12
0
		/// <summary>
		/// Gets path of the xml element start tag that the specified
		/// <paramref name="index"/> is currently inside.
		/// </summary>
		/// <remarks>If the index outside the start tag then an empty path
		/// is returned.</remarks>
		/// <param name="namespaces">Returns the namespaces that are
		/// exist in the xml.</param>
		static XmlElementPath GetActiveElementStartPath(string xml, int index, QualifiedNameCollection namespaces)
		{
			XmlElementPath path = new XmlElementPath();
			string elementText = GetActiveElementStartText(xml, index);
			if (elementText != null) {
				path = GetActiveElementStartPath(xml, index, elementText, namespaces);
			}
			return path;
		}
예제 #13
0
		/// <summary>
		/// Gets path of the xml element start tag that the specified
		/// <paramref name="index"/> is currently located. This is different to the
		/// GetActiveElementStartPath method since the index can be inside the element
		/// name.
		/// </summary>
		/// <remarks>If the index outside the start tag then an empty path
		/// is returned.</remarks>
		static XmlElementPath GetActiveElementStartPathAtIndex(string xml, int index, QualifiedNameCollection namespaces)
		{
			// Find first non xml element name character to the right of the index.
			index = GetCorrectedIndex(xml.Length, index);
			if (index < 0) // can happen when xml.Length==0
				return new XmlElementPath();
			int currentIndex = index;
			for (; currentIndex < xml.Length; ++currentIndex) {
				char ch = xml[currentIndex];
				if (!IsXmlNameChar(ch)) {
					break;
				}
			}
			
			string elementText = GetElementNameAtIndex(xml, currentIndex);
			if (elementText != null) {
				return GetActiveElementStartPath(xml, currentIndex, elementText, namespaces);
			}
			return new XmlElementPath();
		}
예제 #14
0
		/// <summary>
		/// Gets the parent element path based on the index position. This
		/// method does not compact the path so it will include all elements
		/// including those in another namespace in the path.
		/// </summary>
		static XmlElementPath GetFullParentElementPath(string xml, QualifiedNameCollection namespaces)
		{
			XmlElementPath path = new XmlElementPath();
			IDictionary<string,string> namespacesInScope = null;
			using (StringReader reader = new StringReader(xml)) {
				using (XmlTextReader xmlReader = new XmlTextReader(reader)) {
					try {
						xmlReader.XmlResolver = null; // prevent XmlTextReader from loading external DTDs
						while (xmlReader.Read()) {
							switch (xmlReader.NodeType) {
								case XmlNodeType.Element:
									if (!xmlReader.IsEmptyElement) {
										QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix);
										path.Elements.Add(elementName);
									}
									break;
								case XmlNodeType.EndElement:
									path.Elements.RemoveLast();
									break;
							}
						}
					} catch (XmlException) {
						namespacesInScope = xmlReader.GetNamespacesInScope(XmlNamespaceScope.All);
					}
				}
			}
			
			// Add namespaces in scope for the last element read.
			if (namespacesInScope != null) {
				foreach (KeyValuePair<string, string> ns in namespacesInScope) {
					namespaces.Add(new QualifiedName(String.Empty, ns.Value, ns.Key));
				}
			}
			
			return path;
		}
예제 #15
0
		/// <summary>
		/// Finds the namespace for the specified prefix.
		/// </summary>
		static string GetNamespaceForPrefix(QualifiedNameCollection namespaces, string prefix)
		{
			foreach (QualifiedName name in namespaces) {
				if (name.Prefix == prefix) {
					return name.Namespace;
				}
			}
			return String.Empty;
		}
예제 #16
0
        /// <summary>
        /// Gets path of the xml element start tag that the specified
        /// <paramref name="index"/> is currently inside.
        /// </summary>
        /// <remarks>If the index outside the start tag then an empty path
        /// is returned.</remarks>
        public static XmlElementPath GetActiveElementStartPath(string xml, int index)
        {
            QualifiedNameCollection namespaces = new QualifiedNameCollection();

            return(GetActiveElementStartPath(xml, index, namespaces));
        }
예제 #17
0
		/// <summary>
		/// Gets the active element path given the element text.
		/// </summary>
		static XmlElementPath GetActiveElementStartPath(string xml, int index, string elementText, QualifiedNameCollection namespaces)
		{
			QualifiedName elementName = GetElementName(elementText);
			if (elementName == null) {
				return new XmlElementPath();
			}
			
			NamespaceURI elementNamespace = GetElementNamespace(elementText);
			
			XmlElementPath path = GetFullParentElementPath(xml.Substring(0, index), namespaces);
			
			// Try to get a namespace for the active element's prefix.
			if (elementName.Prefix.Length > 0 && elementNamespace.Namespace.Length == 0) {
				elementName.Namespace = GetNamespaceForPrefix(namespaces, elementName.Prefix);
				elementNamespace.Namespace = elementName.Namespace;
				elementNamespace.Prefix = elementName.Prefix;
			}
			
			if (elementNamespace.Namespace.Length == 0) {
				if (path.Elements.Count > 0) {
					QualifiedName parentName = path.Elements[path.Elements.Count - 1];
					elementNamespace.Namespace = parentName.Namespace;
					elementNamespace.Prefix = parentName.Prefix;
				}
			}
			path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Namespace, elementNamespace.Prefix));
			path.Compact();
			return path;
		}
		public void Init()
		{
			qualifiedNames = new QualifiedNameCollection();
		}
예제 #19
0
		/// <summary>
		/// Gets the parent element path based on the index position.
		/// </summary>
		public static XmlElementPath GetParentElementPath(string xml)
		{
			QualifiedNameCollection namespaces = new QualifiedNameCollection();
			XmlElementPath path = GetFullParentElementPath(xml, namespaces);
			path.Compact();
			return path;
		}
 /// <summary>
 ///   Initializes a new instance of <see cref='QualifiedNameCollection'/> based on another <see cref='QualifiedNameCollection'/>.
 /// </summary>
 /// <param name='val'>
 ///   A <see cref='QualifiedNameCollection'/> from which the contents are copied
 /// </param>
 public QualifiedNameCollection(QualifiedNameCollection val)
 {
     this.AddRange(val);
 }
예제 #21
0
        /// <summary>
        /// Gets the active element path given the element text.
        /// </summary>
        static XmlElementPath GetActiveElementStartPath(string xml, int index, string elementText, QualifiedNameCollection namespaces)
        {
            QualifiedName elementName = GetElementName(elementText);

            if (elementName == null)
            {
                return(new XmlElementPath());
            }

            NamespaceURI elementNamespace = GetElementNamespace(elementText);

            XmlElementPath path = GetFullParentElementPath(xml.Substring(0, index), namespaces);

            // Try to get a namespace for the active element's prefix.
            if (elementName.Prefix.Length > 0 && elementNamespace.Namespace.Length == 0)
            {
                elementName.Namespace      = GetNamespaceForPrefix(namespaces, elementName.Prefix);
                elementNamespace.Namespace = elementName.Namespace;
                elementNamespace.Prefix    = elementName.Prefix;
            }

            if (elementNamespace.Namespace.Length == 0)
            {
                if (path.Elements.Count > 0)
                {
                    QualifiedName parentName = path.Elements[path.Elements.Count - 1];
                    elementNamespace.Namespace = parentName.Namespace;
                    elementNamespace.Prefix    = parentName.Prefix;
                }
            }
            path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Namespace, elementNamespace.Prefix));
            path.Compact();
            return(path);
        }
		/// <summary>
		///   Adds the contents of another <see cref='QualifiedNameCollection'/> to the end of the collection.
		/// </summary>
		/// <param name='val'>
		///    A <see cref='QualifiedNameCollection'/> containing the objects to add to the collection.
		/// </param>
		/// <seealso cref='QualifiedNameCollection.Add'/>
		public void AddRange(QualifiedNameCollection val)
		{
			for (int i = 0; i < val.Count; i++)
			{
				this.Add(val[i]);
			}
		}
 public void RemoveLastItemFromEmptyCollectionDoesNotThrowArgumentOutOfRangeException()
 {
     qualifiedNameCollection = new QualifiedNameCollection();
     Assert.DoesNotThrow(delegate { qualifiedNameCollection.RemoveLast(); });
 }
 public void NewQualifiedNameCollectionIsEmpty()
 {
     qualifiedNameCollection = new QualifiedNameCollection();
     Assert.IsTrue(qualifiedNameCollection.IsEmpty);
 }
			/// <summary>
			///   Initializes a new instance of <see cref='QualifiedNameEnumerator'/>.
			/// </summary>
			public QualifiedNameEnumerator(QualifiedNameCollection mappings)
			{
				this.temp = ((IEnumerable)(mappings));
				this.baseEnumerator = temp.GetEnumerator();
			}
예제 #26
0
		/// <summary>
		/// Gets the name of the attribute and its prefix at the specified index. The index
		/// can be anywhere inside the attribute name or in the attribute value.
		/// The namespace for the element containing the attribute will also be determined
		/// if the includeNamespace flag is set to true.
		/// </summary>
		public static QualifiedName GetQualifiedAttributeNameAtIndex(string xml, int index, bool includeNamespace)
		{
			string name = GetAttributeNameAtIndex(xml, index);
			QualifiedName qualifiedName = GetQualifiedName(name);
			if (qualifiedName != null && String.IsNullOrEmpty(qualifiedName.Namespace) && includeNamespace) {
				QualifiedNameCollection namespaces = new QualifiedNameCollection();
				XmlElementPath path = GetActiveElementStartPathAtIndex(xml, index, namespaces);
				qualifiedName.Namespace = GetNamespaceForPrefix(namespaces, path.Elements.LastPrefix);
			}
			return qualifiedName;
		}
		/// <summary>
		///   Initializes a new instance of <see cref='QualifiedNameCollection'/> based on another <see cref='QualifiedNameCollection'/>.
		/// </summary>
		/// <param name='val'>
		///   A <see cref='QualifiedNameCollection'/> from which the contents are copied
		/// </param>
		public QualifiedNameCollection(QualifiedNameCollection val)
		{
			this.AddRange(val);
		}
예제 #28
0
        /// <summary>
        /// Gets path of the xml element start tag that the specified
        /// <paramref name="index"/> is currently located. This is different to the
        /// GetActiveElementStartPath method since the index can be inside the element
        /// name.
        /// </summary>
        /// <remarks>If the index outside the start tag then an empty path
        /// is returned.</remarks>
        static XmlElementPath GetActiveElementStartPathAtIndex(string xml, int index, QualifiedNameCollection namespaces)
        {
            // Find first non xml element name character to the right of the index.
            index = GetCorrectedIndex(xml.Length, index);
            if (index < 0)             // can happen when xml.Length==0
            {
                return(new XmlElementPath());
            }
            int currentIndex = index;

            for (; currentIndex < xml.Length; ++currentIndex)
            {
                char ch = xml[currentIndex];
                if (!IsXmlNameChar(ch))
                {
                    break;
                }
            }

            string elementText = GetElementNameAtIndex(xml, currentIndex);

            if (elementText != null)
            {
                return(GetActiveElementStartPath(xml, currentIndex, elementText, namespaces));
            }
            return(new XmlElementPath());
        }
 /// <summary>
 ///   Initializes a new instance of <see cref='QualifiedNameEnumerator'/>.
 /// </summary>
 public QualifiedNameEnumerator(QualifiedNameCollection mappings)
 {
     this.temp           = ((IEnumerable)(mappings));
     this.baseEnumerator = temp.GetEnumerator();
 }
 public void EmptyQualifiedNameCollectionHasNoItems()
 {
     qualifiedNameCollection = new QualifiedNameCollection();
     Assert.IsFalse(qualifiedNameCollection.HasItems);
 }
		public void Init()
		{
			lhs = new QualifiedNameCollection();
			rhs = new QualifiedNameCollection();			
		}
 public void GetLastPrefixFromEmptyCollectionDoesNotThrowArgumentOutOfRangeException()
 {
     qualifiedNameCollection = new QualifiedNameCollection();
     Assert.AreEqual(String.Empty, qualifiedNameCollection.GetLastPrefix());
 }
예제 #33
0
 public QualifiedNameCollection(QualifiedNameCollection names)
 {
     AddRange(names);
 }
 public void GetLastReturnsNullWhenCollectionIsEmpty()
 {
     qualifiedNameCollection = new QualifiedNameCollection();
     Assert.IsNull(qualifiedNameCollection.GetLast());
 }