public void HashCodeTest()
		{
			QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f");
			XmlQualifiedName xmlQualifiedName = new XmlQualifiedName("foo", "http://foo.com");

			Assert.AreEqual(name1.GetHashCode(), xmlQualifiedName.GetHashCode());
		}		
		public void EqualsTest3()
		{
			QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f");
			QualifiedName name2 = new QualifiedName("foo", "http://foo.com", "ggg");
			
			Assert.IsTrue(name1 == name2, "Should be the same.");
		}	
		public void NotEqualsTest2()
		{
			QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f");
			QualifiedName name2 = null; 
			
			Assert.IsFalse(name1 == name2, "Should not be the same.");
		}
		public void EqualsTest2()
		{
			QualifiedName name1 = new QualifiedName("foo", "http://foo.com", "f");
			QualifiedName name2 = new QualifiedName("foo", "http://foo.com", "f");
			
			Assert.AreEqual(name1, name2, "Should be the same.");
		}		
		public void Init()
		{
			path = new XmlElementPath();
			firstQualifiedName = new QualifiedName("foo", "http://foo", "f");
			path.Elements.Add(firstQualifiedName);
			
			secondQualifiedName = new QualifiedName("bar", "http://bar", "b");
			path.Elements.Add(secondQualifiedName);
		}
		public override void FixtureInit()
		{
			// Note element path.
			noteElementPath = new XmlElementPath();
			QualifiedName noteQualifiedName = new QualifiedName("note", "http://www.w3schools.com");
			noteElementPath.Elements.Add(noteQualifiedName);
		
			// Text element path.
			textElementPath = new XmlElementPath();
			textElementPath.Elements.Add(noteQualifiedName);
			textElementPath.Elements.Add(new QualifiedName("text", "http://www.w3schools.com"));
		}	
		public override void FixtureInit()
		{
			// Get shipto attributes.
			shipToPath = new XmlElementPath();
			QualifiedName shipOrderName = new QualifiedName("shiporder", "http://www.w3schools.com");
			shipToPath.Elements.Add(shipOrderName);
			shipToPath.Elements.Add(new QualifiedName("shipto", "http://www.w3schools.com"));

			shipToAttributes = SchemaCompletionData.GetAttributeCompletionData(shipToPath);
			
			// Get shiporder attributes.
			shipOrderPath = new XmlElementPath();
			shipOrderPath.Elements.Add(shipOrderName);
			
			shipOrderAttributes = SchemaCompletionData.GetAttributeCompletionData(shipOrderPath);
			
		}
Beispiel #8
0
		/// <summary>
		/// Gets the element name from the element start tag string.
		/// </summary>
		/// <param name="xml">This string must start at the 
		/// element we are interested in.</param>
		static QualifiedName GetElementName(string xml)
		{
			string name = String.Empty;
			
			// Find the end of the element name.
			xml = xml.Replace("\r\n", " ");
			int index = xml.IndexOf(' ');
			if (index > 0) {
				name = xml.Substring(1, index - 1);
			} else {
				name = xml.Substring(1);
			}
			
			QualifiedName qualifiedName = new QualifiedName();
			
			int prefixIndex = name.IndexOf(':');
			if (prefixIndex > 0) {
				qualifiedName.Prefix = name.Substring(0, prefixIndex);
				qualifiedName.Name = name.Substring(prefixIndex + 1);
			} else {
				qualifiedName.Name = name;
			}
			
			return qualifiedName;
		}		
		/// <summary>
		///   Initializes a new instance of <see cref='QualifiedNameCollection'/> containing any array of <see cref='QualifiedName'/> objects.
		/// </summary>
		/// <param name='val'>
		///       A array of <see cref='QualifiedName'/> objects with which to intialize the collection
		/// </param>
		public QualifiedNameCollection(QualifiedName[] val)
		{
			this.AddRange(val);
		}
		/// <summary>
		///   Removes a specific <see cref='QualifiedName'/> from the <see cref='QualifiedNameCollection'/>.
		/// </summary>
		/// <param name='val'>The <see cref='QualifiedName'/> to remove from the <see cref='QualifiedNameCollection'/>.</param>
		/// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
		public void Remove(QualifiedName val)
		{
			List.Remove(val);
		}
		/// <summary>
		///   Inserts a <see cref='QualifiedName'/> into the <see cref='QualifiedNameCollection'/> at the specified index.
		/// </summary>
		/// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
		/// <param name='val'>The <see cref='QualifiedName'/> to insert.</param>
		/// <seealso cref='QualifiedNameCollection.Add'/>
		public void Insert(int index, QualifiedName val)
		{
			List.Insert(index, val);
		}
		/// <summary>
		///    Returns the index of a <see cref='QualifiedName'/> in 
		///       the <see cref='QualifiedNameCollection'/>.
		/// </summary>
		/// <param name='val'>The <see cref='QualifiedName'/> to locate.</param>
		/// <returns>
		///   The index of the <see cref='QualifiedName'/> of <paramref name='val'/> in the 
		///   <see cref='QualifiedNameCollection'/>, if found; otherwise, -1.
		/// </returns>
		/// <seealso cref='QualifiedNameCollection.Contains'/>
		public int IndexOf(QualifiedName val)
		{
			return List.IndexOf(val);
		}
		/// <summary>
		///   Copies the <see cref='QualifiedNameCollection'/> values to a one-dimensional <see cref='Array'/> instance at the 
		///    specified index.
		/// </summary>
		/// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='QualifiedNameCollection'/>.</param>
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
		/// <exception cref='ArgumentException'>
		///   <para><paramref name='array'/> is multidimensional.</para>
		///   <para>-or-</para>
		///   <para>The number of elements in the <see cref='QualifiedNameCollection'/> is greater than
		///         the available space between <paramref name='arrayIndex'/> and the end of
		///         <paramref name='array'/>.</para>
		/// </exception>
		/// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
		/// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
		/// <seealso cref='Array'/>
		public void CopyTo(QualifiedName[] array, int index)
		{
			List.CopyTo(array, index);
		}
		/// <summary>
		///   Gets a value indicating whether the 
		///    <see cref='QualifiedNameCollection'/> contains the specified <see cref='QualifiedName'/>.
		/// </summary>
		/// <param name='val'>The <see cref='QualifiedName'/> to locate.</param>
		/// <returns>
		/// <see langword='true'/> if the <see cref='QualifiedName'/> is contained in the collection; 
		///   otherwise, <see langword='false'/>.
		/// </returns>
		/// <seealso cref='QualifiedNameCollection.IndexOf'/>
		public bool Contains(QualifiedName val)
		{
			return List.Contains(val);
		}
		static XmlElementPath ConvertPath (IEnumerable<XElement> path)
		{
			XmlElementPath elementPath = new XmlElementPath ();
			var namespaces = new Dictionary<string, string> ();
			string defaultNamespace = null;
			foreach (XElement el in path) {
				foreach (XAttribute att in el.Attributes) {
					if (att.Name.HasPrefix) {
						if (att.Name.Prefix == "xmlns")
							namespaces [att.Name.Name] = att.Value;
					} else {
						if (att.Name.Name == "xmlns")
							defaultNamespace = att.Value;
					}
				}
				string ns = null;
				if (el.Name.HasPrefix)
					namespaces.TryGetValue (el.Name.Prefix, out ns);
				else
					ns = defaultNamespace;
				QualifiedName qn = new QualifiedName (el.Name.Name, ns, el.Name.Prefix ?? String.Empty);
				elementPath.Elements.Add (qn);
			}
			return elementPath;
		}
		/// <summary>
		///   Adds a <see cref='QualifiedName'/> with the specified value to the 
		///   <see cref='QualifiedNameCollection'/>.
		/// </summary>
		/// <param name='val'>The <see cref='QualifiedName'/> to add.</param>
		/// <returns>The index at which the new element was inserted.</returns>
		/// <seealso cref='QualifiedNameCollection.AddRange'/>
		public int Add(QualifiedName val)
		{
			return List.Add(val);
		}
		public void Init()
		{
			path = new XmlElementPath();
			qualifiedName = new QualifiedName("foo", "http://foo");
			path.Elements.Add(qualifiedName);
		}
		/// <summary>
		///   Copies the elements of an array to the end of the <see cref='QualifiedNameCollection'/>.
		/// </summary>
		/// <param name='val'>
		///    An array of type <see cref='QualifiedName'/> containing the objects to add to the collection.
		/// </param>
		/// <seealso cref='QualifiedNameCollection.Add'/>
		public void AddRange(QualifiedName[] val)
		{
			for (int i = 0; i < val.Length; i++) {
				this.Add(val[i]);
			}
		}
		XmlElementPath ConvertPath (IList<XObject> path)
		{
			var elementPath = new XmlElementPath ();
			
			if (defaultSchemaCompletionData != null && !string.IsNullOrEmpty (defaultSchemaCompletionData.NamespaceUri))
				elementPath.Namespaces.AddPrefix (defaultSchemaCompletionData.NamespaceUri, defaultNamespacePrefix ?? "");
			
			foreach (var obj in path) {
				var el = obj as XElement;
				if (el == null)
					continue;
				foreach (var att in el.Attributes) {
					if (!string.IsNullOrEmpty (att.Value)) {
						if (att.Name.HasPrefix) {
							if (att.Name.Prefix == "xmlns")
								elementPath.Namespaces.AddPrefix (att.Value, att.Name.Name);
						} else if (att.Name.Name == "xmlns") {
								elementPath.Namespaces.AddPrefix (att.Value, "");
						}
					}
				}
				string ns = elementPath.Namespaces.GetNamespace (el.Name.HasPrefix? el.Name.Prefix : "");
				QualifiedName qn = new QualifiedName (el.Name.Name, ns, el.Name.Prefix ?? String.Empty);
				elementPath.Elements.Add (qn);
			}
			return elementPath;
		}
Beispiel #20
0
		/// <summary>
		/// Gets the parent element path based on the index position.
		/// </summary>
		public static XmlElementPath GetParentElementPath(string xml)
		{
			XmlElementPath path = new XmlElementPath();
			
			try {
				StringReader reader = new StringReader(xml);
				XmlTextReader xmlReader = new XmlTextReader(reader);
				xmlReader.XmlResolver = null;
				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) { 
				// Do nothing.
			} catch (WebException) {
				// Do nothing.
			}
			
			path.Compact();
			
			return path;
		}