void SetCompletionWindowWidth(ICompletionListWindow completionWindow, XmlCompletionItemCollection completionItems)
		{
			XmlCompletionItem firstListItem = completionItems[0];
			if (firstListItem.DataType == XmlCompletionItemType.NamespaceUri) {
				completionWindow.Width = double.NaN;
			}
		}
		public override void FixtureInit()
		{
			XmlElementPath path = new XmlElementPath();
			path.AddElement(new QualifiedName("foo", "http://foo.com"));
			
			attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path);
		}
		public override void FixtureInit()
		{
			XmlElementPath path = new XmlElementPath();
			path.AddElement(new QualifiedName("root", "http://foo"));
			path.AddElement(new QualifiedName("bar", "http://foo"));
			barElementAttributes = SchemaCompletion.GetAttributeCompletion(path);
		}
        public override void FixtureInit()
        {
            XmlElementPath path = new XmlElementPath();
            path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));

            noteChildElements = SchemaCompletion.GetChildElementCompletion(path);
        }
        public override void FixtureInit()
        {
            XmlElementPath path = new XmlElementPath();
            path.AddElement(new QualifiedName("foo", "http://foo.com"));

            fooChildElementCompletion = SchemaCompletion.GetChildElementCompletion(path);
        }
        public override void FixtureInit()
        {
            XmlElementPath path = new XmlElementPath();
            path.AddElement(new QualifiedName("html", "http://foo/xhtml"));

            htmlChildElements = SchemaCompletion.GetChildElementCompletion(path);
        }
		public override void FixtureInit()
		{
			XmlElementPath path = new XmlElementPath();
			path.AddElement(new QualifiedName("schema", "http://www.w3.org/2001/XMLSchema"));
			
			schemaChildElements = SchemaCompletion.GetChildElementCompletion(path);
			schemaAttributes = SchemaCompletion.GetAttributeCompletion(path);
			
			// Get include elements attributes.
			path.AddElement(new QualifiedName("include", "http://www.w3.org/2001/XMLSchema"));
			includeAttributes = SchemaCompletion.GetAttributeCompletion(path);
		
			// Get annotation element info.
			path.Elements.RemoveLast();
			path.AddElement(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema"));
			
			annotationChildElements = SchemaCompletion.GetChildElementCompletion(path);
			annotationAttributes = SchemaCompletion.GetAttributeCompletion(path);
		
			// Get app info attributes.
			path.AddElement(new QualifiedName("appinfo", "http://www.w3.org/2001/XMLSchema"));
			appInfoAttributes = SchemaCompletion.GetAttributeCompletion(path);
			
			// Get foo attributes.
			path = new XmlElementPath();
			path.AddElement(new QualifiedName("foo", "http://www.w3.org/2001/XMLSchema"));
			fooAttributes = SchemaCompletion.GetAttributeCompletion(path);
		}
		public void CanGetCompletionItemsUsedAsShowCompletionMethodParameters()
		{
			XmlCompletionItemCollection list = new XmlCompletionItemCollection();
			list.Add(new XmlCompletionItem("a"));
			editor.ShowCompletionWindow(list);

			Assert.AreSame(list, editor.CompletionItemsDisplayed);
		}
		public void LinkElementHasAddressAndXlinkHrefAttribute()
		{
			XmlCompletionItemCollection expectedAttributes = new XmlCompletionItemCollection();
			expectedAttributes.Add(new XmlCompletionItem("address", XmlCompletionItemType.XmlAttribute));
			expectedAttributes.Add(new XmlCompletionItem("xlink:href", XmlCompletionItemType.XmlAttribute));
			
			Assert.AreEqual(expectedAttributes.ToArray(), linkElementAttributes.ToArray());
		}
		public override void FixtureInit()
		{
			XmlElementPath path = new XmlElementPath();
			path.AddElement(new QualifiedName("note", "http://www.w3schools.com"));
			
			attributeCompletionItems = SchemaCompletion.GetAttributeCompletion(path);
			attributeName = attributeCompletionItems[0].Text;
		}
        public void ListCompleteMethodCallsCompletionItemCompleteMethod()
        {
            CompletionContext context = new CompletionContext();
            XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
            completionItems.Complete(context, this);

            Assert.AreSame(contextPassedToCompleteMethod, context);
        }
		public override void FixtureInit()
		{
			XmlElementPath path = new XmlElementPath();
			path.AddElement(new QualifiedName("project", "http://nant.sf.net//nant-0.84.xsd"));
			path.AddElement(new QualifiedName("attrib", "http://nant.sf.net//nant-0.84.xsd"));
			
			attributes = SchemaCompletion.GetAttributeCompletion(path);
		}
		public void Init()
		{
			firstItem = new XmlCompletionItem("text", "desc-1", XmlCompletionItemType.XmlElement);
			secondItem = new XmlCompletionItem("text2", "desc-2", XmlCompletionItemType.XmlAttribute);
			
			itemCollection = new XmlCompletionItemCollection();
			itemCollection.Add(firstItem);
			itemCollection.Add(secondItem);
		}
		public void ExpectedCompletionDataItems()
		{
			XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
			expectedItems.Add(new XmlCompletionItem("a", XmlCompletionItemType.NamespaceUri));
			expectedItems.Add(new XmlCompletionItem("b", XmlCompletionItemType.NamespaceUri));
			expectedItems.Add(new XmlCompletionItem("c", XmlCompletionItemType.NamespaceUri));
			
			Assert.AreEqual(expectedItems.ToArray(), textEditor.CompletionItemsDisplayedToArray());
		}
		public override void FixtureInit()
		{
			XmlElementPath path = new XmlElementPath();
			path.AddElement(new QualifiedName("link", schemaNamespace));
			path.NamespacesInScope.Add(new XmlNamespace("xlink", "http://www.w3.org/1999/xlink"));
			
			linkElementAttributes = SchemaCompletion.GetAttributeCompletion(path);
			linkElementAttributes.Sort();
		}
		public void CanCheckCompletionWindowFromShowCompletionHasWidthPropertyModified()
		{
			XmlCompletionItemCollection list = new XmlCompletionItemCollection();
			list.Add(new XmlCompletionItem("a"));
			ICompletionListWindow window = editor.ShowCompletionWindow(list);
			window.Width = double.NaN;
			
			Assert.AreEqual(double.NaN, editor.CompletionWindowDisplayed.Width);
		}
        public override void FixtureInit()
        {
            XmlElementPath path = new XmlElementPath();
            path.AddElement(new QualifiedName("person", "http://foo"));
            personElementChildren = SchemaCompletion.GetChildElementCompletion(path);

            path.AddElement(new QualifiedName("firstname", "http://foo"));
            firstNameAttributes = SchemaCompletion.GetAttributeCompletion(path);
            firstNameElementChildren = SchemaCompletion.GetChildElementCompletion(path);
        }
		public void CanConvertCompletionItemsUsedAsShowCompletionMethodParametersToArray()
		{
			XmlCompletionItem item = new XmlCompletionItem("a");
			List<XmlCompletionItem> expectedArray = new List<XmlCompletionItem>();
			expectedArray.Add(item);
			
			XmlCompletionItemCollection list = new XmlCompletionItemCollection();
			list.Add(item);
			editor.ShowCompletionWindow(list);

			Assert.AreEqual(expectedArray.ToArray(), editor.CompletionItemsDisplayedToArray());
		}
		public void FixtureInit()
		{
			XmlSchemaCompletionCollection items = new XmlSchemaCompletionCollection();
			
			StringReader reader = new StringReader(GetSchema(firstNamespace));
			XmlSchemaCompletion schema = new XmlSchemaCompletion(reader);
			items.Add(schema);
			
			reader = new StringReader(GetSchema(secondNamespace));
			schema = new XmlSchemaCompletion(reader);
			items.Add(schema);
			namespaceCompletionItems = items.GetNamespaceCompletion();
		}
		public void FixtureInit()
		{
			schemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema());
			
			// Set up h1 element's path.
			h1Path = new XmlElementPath();
			h1Path.AddElement(new QualifiedName("html", namespaceURI));
			h1Path.AddElement(new QualifiedName("body", namespaceURI));
			h1Path.AddElement(new QualifiedName("h1", namespaceURI));
			
			// Get h1 element info.
			h1Attributes = schemaCompletion.GetAttributeCompletion(h1Path);
		}
        public void GetAttributeCompletionReturnsAttributesFromDuplicateFooSchema()
        {
            string xml =
                "<duplicate-foo-note xmlns='foo'>\r\n" +
                "        <duplicate-foo-text ";

            XmlCompletionItemCollection items = schemas.GetAttributeCompletion(xml, null);

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
            expectedItems.Add(new XmlCompletionItem("duplicate-foo-text-attribute", XmlCompletionItemType.XmlAttribute));

            Assert.AreEqual(expectedItems, items);
        }
		public override void FixtureInit()
		{
			XmlElementPath path = new XmlElementPath();
			
			path.AddElement(new QualifiedName("project", "http://foo"));
			path.AddElement(new QualifiedName("items", "http://foo"));
			
			itemsElementChildren = SchemaCompletion.GetChildElementCompletion(path);
			
			path.AddElement(new QualifiedName("file", "http://foo"));
			
			fileElementAttributes = SchemaCompletion.GetAttributeCompletion(path);
			fileElementChildren = SchemaCompletion.GetChildElementCompletion(path);
		}
        public void DefaultSchemaRootElementsReturnedWhenNoNamespaceExplicitlyDefinedInXmlAndXmlIsEmpty()
        {
            XmlSchemaCompletion defaultSchema = schemas["foo"];
            string xml = "<";

            XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, defaultSchema);

            items.Sort();

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();

            expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement));

            Assert.AreEqual(expectedItems, items);
        }
Example #24
0
        public void GetChildElementCompletionForDuplicateFooRootElement()
        {
            XmlElementPath path = new XmlElementPath();

            path.AddElement(new QualifiedName("duplicate-foo-note", "foo"));
            XmlCompletionItemCollection items = schemas.GetChildElementCompletion(path, null);

            items.Sort();

            List <XmlCompletionItem> expectedItems = new List <XmlCompletionItem>();

            expectedItems.Add(new XmlCompletionItem("duplicate-foo-text", XmlCompletionItemType.XmlElement));

            Assert.AreEqual(expectedItems.ToArray(), items.ToArray());
        }
        public override void FixtureInit()
        {
            XmlElementPath path = new XmlElementPath();
            path.AddElement(new QualifiedName("group", "http://www.w3.org/2001/XMLSchema"));
            childElements = SchemaCompletion.GetChildElementCompletion(path);
            attributes = SchemaCompletion.GetAttributeCompletion(path);

            // Get annotation child elements.
            path.AddElement(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema"));
            annotationChildElements = SchemaCompletion.GetChildElementCompletion(path);

            // Get choice child elements.
            path.Elements.RemoveLast();
            path.AddElement(new QualifiedName("choice", "http://www.w3.org/2001/XMLSchema"));
            choiceChildElements = SchemaCompletion.GetChildElementCompletion(path);
        }
        public override void FixtureInit()
        {
            // Get shipto attributes.
            shipToPath = new XmlElementPath();
            QualifiedName shipOrderName = new QualifiedName("shiporder", "http://www.w3schools.com");
            shipToPath.AddElement(shipOrderName);
            shipToPath.AddElement(new QualifiedName("shipto", "http://www.w3schools.com"));

            shipToAttributes = SchemaCompletion.GetAttributeCompletion(shipToPath);

            // Get shiporder attributes.
            shipOrderPath = new XmlElementPath();
            shipOrderPath.AddElement(shipOrderName);

            shipOrderAttributes = SchemaCompletion.GetAttributeCompletion(shipOrderPath);
        }
        public void DefaultSchemaRootElementsReturnedOnceWhenNamespaceDefinedButNoElementsExistForthatNamespace()
        {
            XmlSchemaCompletion defaultSchema = schemas["foo"];
            string xml = "<b:bar-note xmlns='foo' xmlns:b='bar'><";

            XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, defaultSchema);

            items.Sort();

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();

            expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement));
            expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement));

            Assert.AreEqual(expectedItems, items);
        }
        public void CorrectAttributesReturnedForElementWhenTwoNamespacesInXml()
        {
            string xml =
                "<b:bar-note xmlns='foo' xmlns:b='bar'>\r\n" +
                "    <foo-note>\r\n" +
                "        <b:bar-text/>\r\n" +
                "        <foo-text ";

            XmlCompletionItemCollection items = schemas.GetAttributeCompletion(xml, null);

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();

            expectedItems.Add(new XmlCompletionItem("foo-text-attribute", XmlCompletionItemType.XmlAttribute));

            Assert.AreEqual(expectedItems, items);
        }
        public void Init()
        {
            XmlCompletionItem lastItem = new XmlCompletionItem("cc", XmlCompletionItemType.XmlElement);
            XmlCompletionItem secondItem = new XmlCompletionItem("bb", XmlCompletionItemType.XmlElement);
            XmlCompletionItem firstItem = new XmlCompletionItem("aa", XmlCompletionItemType.XmlElement);

            XmlCompletionItemCollection collection = new XmlCompletionItemCollection();
            collection.Add(lastItem);
            collection.Add(secondItem);
            collection.Add(firstItem);

            expectedCompletionItems = new XmlCompletionItem[] { firstItem, secondItem, lastItem };

            completionItems = new XmlCompletionItemCollection(collection);
            completionItems.Sort();
        }
Example #30
0
        public void GetRootElementCompletionReturnsRootElementsFromBothFooSchemas()
        {
            XmlNamespaceCollection namespaces = new XmlNamespaceCollection();

            namespaces.Add(new XmlNamespace(String.Empty, "foo"));
            XmlCompletionItemCollection items = schemas.GetRootElementCompletion(namespaces);

            items.Sort();

            List <XmlCompletionItem> expectedItems = new List <XmlCompletionItem>();

            expectedItems.Add(new XmlCompletionItem("duplicate-foo-note", XmlCompletionItemType.XmlElement));
            expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement));

            Assert.AreEqual(expectedItems.ToArray(), items.ToArray());
        }
        public void UnusedNamespaceInScopeCannotBeFoundInSchemaCollection()
        {
            XmlElementPath path = new XmlElementPath();

            path.NamespacesInScope.Add(new XmlNamespace("b", "namespace-which-does-not-exist-in-schema-collection"));
            path.AddElement(new QualifiedName("foo-note", "foo"));

            XmlCompletionItemCollection items = schemas.GetElementCompletionForAllNamespaces(path, null);

            items.Sort();

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();

            expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement));

            Assert.AreEqual(expectedItems, items);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="editor"></param>
        /// <param name="defaultSchema"></param>
        /// <param name="hasOpenToken"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        protected XmlCompletionItemCollection GetCompletionItems(XmlSchemaCompletion defaultSchema, XmlSchemaCompletionCollection schemas)
        {
            XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();

            int    offset         = this.Position.Offset;
            string textUpToCursor = this.Text.GetText(0, offset);

            if (XmlParser.IsInsideAttributeValue(textUpToCursor, offset))
            {
                completionItems.AddRange(this.GetCompletionItemsInsideAttribute(defaultSchema, schemas));
            }
            else
            {
                completionItems.AddRange(this.GetCompletionItemsForAttribute(defaultSchema, schemas));
            }
            return(completionItems);
        }
        public override void FixtureInit()
        {
            XmlElementPath path = new XmlElementPath();

            path.AddElement(new QualifiedName("group", "http://www.w3.org/2001/XMLSchema"));
            childElements = SchemaCompletion.GetChildElementCompletion(path);
            attributes    = SchemaCompletion.GetAttributeCompletion(path);

            // Get annotation child elements.
            path.AddElement(new QualifiedName("annotation", "http://www.w3.org/2001/XMLSchema"));
            annotationChildElements = SchemaCompletion.GetChildElementCompletion(path);

            // Get choice child elements.
            path.Elements.RemoveLast();
            path.AddElement(new QualifiedName("choice", "http://www.w3.org/2001/XMLSchema"));
            choiceChildElements = SchemaCompletion.GetChildElementCompletion(path);
        }
        public override void FixtureInit()
        {
            // Get shipto attributes.
            shipToPath = new XmlElementPath();
            QualifiedName shipOrderName = new QualifiedName("shiporder", "http://www.w3schools.com");

            shipToPath.AddElement(shipOrderName);
            shipToPath.AddElement(new QualifiedName("shipto", "http://www.w3schools.com"));

            shipToAttributes = SchemaCompletion.GetAttributeCompletion(shipToPath);

            // Get shiporder attributes.
            shipOrderPath = new XmlElementPath();
            shipOrderPath.AddElement(shipOrderName);

            shipOrderAttributes = SchemaCompletion.GetAttributeCompletion(shipOrderPath);
        }
        public void FooSchemaRootElementAndBarRootElementInPath()
        {
            XmlElementPath path = new XmlElementPath();

            path.AddElement(new QualifiedName("foo-note", "foo"));
            path.AddElement(new QualifiedName("bar-note", "bar", "b"));
            XmlCompletionItemCollection items = schemas.GetElementCompletionForAllNamespaces(path, null);

            items.Sort();

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();

            expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement));
            expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement));

            Assert.AreEqual(expectedItems, items);
        }
		XmlCompletionItemCollection GetCompletionItems(ITextEditor editor, XmlSchemaCompletion defaultSchema)
		{
			int offset = editor.Caret.Offset;
			string textUpToCursor = editor.Document.GetText(0, offset);
			
			XmlCompletionItemCollection items = new XmlCompletionItemCollection();
			if (XmlParser.IsInsideAttributeValue(textUpToCursor, offset)) {
				items = schemas.GetNamespaceCompletion(textUpToCursor);
				if (items.Count == 0)
					items = schemas.GetAttributeValueCompletion(textUpToCursor, editor.Caret.Offset, defaultSchema);
			} else {
				items = schemas.GetAttributeCompletion(textUpToCursor, defaultSchema);
				if (items.Count == 0)
					items = schemas.GetElementCompletion(textUpToCursor, defaultSchema);
			}
			return items;
		}
Example #37
0
        public void Init()
        {
            XmlCompletionItem lastItem   = new XmlCompletionItem("cc", XmlCompletionItemType.XmlElement);
            XmlCompletionItem secondItem = new XmlCompletionItem("bb", XmlCompletionItemType.XmlElement);
            XmlCompletionItem firstItem  = new XmlCompletionItem("aa", XmlCompletionItemType.XmlElement);

            XmlCompletionItemCollection collection = new XmlCompletionItemCollection();

            collection.Add(lastItem);
            collection.Add(secondItem);
            collection.Add(firstItem);

            expectedCompletionItems = new XmlCompletionItem[] { firstItem, secondItem, lastItem };

            completionItems = new XmlCompletionItemCollection(collection);
            completionItems.Sort();
        }
        public void FooSchemaElementAndBarElementInXml()
        {
            string xml =
                "<foo-note xmlns='foo' xmlns:b='bar'>\r\n" +
                "    <b:bar-note>\r\n" +
                "        <";

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();

            expectedItems.Add(new XmlCompletionItem("b:bar-text", XmlCompletionItemType.XmlElement));
            expectedItems.Add(new XmlCompletionItem("foo-text", XmlCompletionItemType.XmlElement));

            XmlCompletionItemCollection items = schemas.GetElementCompletion(xml, null);

            items.Sort();

            Assert.AreEqual(expectedItems, items);
        }
        public void GetAttributeValueCompletionReturnsValuesForDuplicateFooSchema()
        {
            string xml =
                "<duplicate-foo-note xmlns='foo'>\r\n" +
                "    <duplicate-foo-text duplicate-foo-text-attribute='f'";

            string xmlUpToCursor = xml.Substring(0, xml.Length - 1);

            XmlCompletionItemCollection items = schemas.GetAttributeValueCompletion('f', xmlUpToCursor, null);
            items.Sort();

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
            expectedItems.Add(new XmlCompletionItem("first", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("fourth", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("second", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("third", XmlCompletionItemType.XmlAttributeValue));

            Assert.AreEqual(expectedItems, items);
        }
        protected XmlCompletionItemCollection GetCompletionItemsForAttribute(XmlSchemaCompletion defaultSchema, XmlSchemaCompletionCollection schemas)
        {
            int    offset         = this.Position.Offset;
            string textUpToCursor = this.Text.GetText(0, offset);
            XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();

            completionItems = schemas.GetAttributeCompletion(textUpToCursor, defaultSchema);
            if (completionItems.Count == 0)
            {
                completionItems = schemas.GetElementCompletion(textUpToCursor, defaultSchema);
                if (this.HasOpenToken == false)
                {
                    completionItems.Select(i => { i.Text = "<" + i.Text; return(i); }).ToList();
                }
                completionItems.Add(new XmlCompletionItem("<?"));
                completionItems.Add(new XmlCompletionItem("<!--"));
            }

            return(completionItems);
        }
Example #41
0
        public void GetAttributeValueCompletionReturnsValuesForDuplicateFooSchema()
        {
            string xml =
                "<duplicate-foo-note xmlns='foo'>\r\n" +
                "    <duplicate-foo-text duplicate-foo-text-attribute='f'";

            string xmlUpToCursor = xml.Substring(0, xml.Length - 1);

            XmlCompletionItemCollection items = schemas.GetAttributeValueCompletion('f', xmlUpToCursor, null);

            items.Sort();

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();

            expectedItems.Add(new XmlCompletionItem("first", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("fourth", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("second", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("third", XmlCompletionItemType.XmlAttributeValue));

            Assert.AreEqual(expectedItems, items);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="editor"></param>
        /// <returns></returns>
        public XmlCompletionItemCollection RetrieveCompletionItemCollection()
        {
            XmlSchemaCompletionCollection schemas = this.AutoFindSchemaCollection();

            //retrieve information about the path that we are working
            int offset = this.FixOffset(this.Text, this.Position.Offset);

            if (offset == -1)
            {
                return(null);
            }

            string              textUpToCursor = this.Text.GetText(0, offset);
            XmlElementPath      path           = XmlParser.GetActiveElementStartPath(textUpToCursor, textUpToCursor.Length);
            XmlSchemaCompletion defaultSchema  = GetDefaultSchema(path, schemas);

            XmlCompletionItemCollection completionItems = GetCompletionItems(defaultSchema, schemas);

            completionItems.Sort();

            return(completionItems);
        }
        public void CorrectAttributeValuesReturnedForElementWhenTwoNamespacesInXml()
        {
            string xml =
                "<b:bar-note xmlns='foo' xmlns:b='bar'>\r\n" +
                "    <foo-note>\r\n" +
                "        <b:bar-text/>\r\n" +
                "        <foo-text foo-text-attribute='f'";

            string xmlUpToCursor = xml.Substring(0, xml.Length - 1);

            XmlCompletionItemCollection items = schemas.GetAttributeValueCompletion('f', xmlUpToCursor, null);

            items.Sort();

            XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();

            expectedItems.Add(new XmlCompletionItem("first", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("fourth", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("second", XmlCompletionItemType.XmlAttributeValue));
            expectedItems.Add(new XmlCompletionItem("third", XmlCompletionItemType.XmlAttributeValue));

            Assert.AreEqual(expectedItems, items);
        }
		XmlCompletionItemCollection GetAttributeValueCompletion(XmlSchemaAttribute attribute)
		{
			XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
			
			if (attribute.SchemaType != null) {
				XmlSchemaSimpleTypeRestriction simpleTypeRestriction = attribute.SchemaType.Content as XmlSchemaSimpleTypeRestriction;
				if (simpleTypeRestriction != null) {
					completionItems.AddRange(GetAttributeValueCompletion(simpleTypeRestriction));
				}
			} else if (attribute.AttributeSchemaType != null) {
				XmlSchemaSimpleType simpleType = attribute.AttributeSchemaType as XmlSchemaSimpleType;
				
				if (simpleType != null) {
					if (simpleType.Datatype.TypeCode == XmlTypeCode.Boolean) {
						completionItems.AddRange(GetBooleanAttributeValueCompletion());
					} else {
						completionItems.AddRange(GetAttributeValueCompletion(simpleType));
					}
				}
			}
			
			return completionItems;
		}
		XmlCompletionItemCollection GetAttributeValueCompletion(XmlSchemaElement element, string name)
		{
			XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
			
			XmlSchemaComplexType complexType = GetElementAsComplexType(element);
			if (complexType != null) {
				XmlSchemaAttribute attribute = FindAttribute(complexType, name);
				if (attribute != null) {
					completionItems.AddRange(GetAttributeValueCompletion(attribute));
				}
			}
			
			return completionItems;
		}
		/// <summary>
		/// Adds an attribute to the completion data collection.
		/// </summary>
		/// <remarks>
		/// Note the special handling of xml:lang attributes.
		/// </remarks>
		void AddAttribute(XmlCompletionItemCollection completionItems, XmlSchemaAttribute attribute, XmlNamespaceCollection namespacesInScope)
		{
			string name = attribute.Name;
			if (name == null) {
				if (attribute.RefName.Namespace == "http://www.w3.org/XML/1998/namespace") {
					name = String.Concat("xml:", attribute.RefName.Name);
				} else {
					string prefix = namespacesInScope.GetPrefix(attribute.RefName.Namespace);
					if (!String.IsNullOrEmpty(prefix)) {
						name = String.Concat(prefix, ":", attribute.RefName.Name);
					}
				}
			}
			
			if (name != null) {
				string documentation = GetDocumentation(attribute.Annotation);
				XmlCompletionItem item = new XmlCompletionItem(name, documentation, XmlCompletionItemType.XmlAttribute);
				completionItems.Add(item);
			}
		}
        public void FixtureInit()
        {
            schemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());

            // Set up choice element's path.
            choicePath = new XmlElementPath();
            choicePath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
            choicePath.AddElement(new QualifiedName("element", namespaceURI, prefix));
            choicePath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));

            mixedAttributeValues = schemaCompletion.GetAttributeValueCompletion(choicePath, "mixed");

            choicePath.AddElement(new QualifiedName("choice", namespaceURI, prefix));

            // Get choice element info.
            choiceAttributes         = schemaCompletion.GetAttributeCompletion(choicePath);
            maxOccursAttributeValues = schemaCompletion.GetAttributeValueCompletion(choicePath, "maxOccurs");

            // Set up element path.
            elementPath = new XmlElementPath();
            elementPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));

            elementFormDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "elementFormDefault");
            blockDefaultAttributeValues       = schemaCompletion.GetAttributeValueCompletion(elementPath, "blockDefault");
            finalDefaultAttributeValues       = schemaCompletion.GetAttributeValueCompletion(elementPath, "finalDefault");

            elementPath.AddElement(new QualifiedName("element", namespaceURI, prefix));

            // Get element attribute info.
            elementAttributes = schemaCompletion.GetAttributeCompletion(elementPath);

            // Set up simple enum type path.
            simpleEnumPath = new XmlElementPath();
            simpleEnumPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
            simpleEnumPath.AddElement(new QualifiedName("simpleType", namespaceURI, prefix));
            simpleEnumPath.AddElement(new QualifiedName("restriction", namespaceURI, prefix));

            // Get child elements.
            simpleEnumElements = schemaCompletion.GetChildElementCompletion(simpleEnumPath);

            // Set up enum path.
            enumPath = new XmlElementPath();
            enumPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
            enumPath.AddElement(new QualifiedName("simpleType", namespaceURI, prefix));
            enumPath.AddElement(new QualifiedName("restriction", namespaceURI, prefix));
            enumPath.AddElement(new QualifiedName("enumeration", namespaceURI, prefix));

            // Get attributes.
            enumAttributes = schemaCompletion.GetAttributeCompletion(enumPath);

            // Set up xs:all path.
            allElementPath = new XmlElementPath();
            allElementPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
            allElementPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
            allElementPath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));
            allElementPath.AddElement(new QualifiedName("all", namespaceURI, prefix));

            // Get child elements of the xs:all element.
            allElementChildElements = schemaCompletion.GetChildElementCompletion(allElementPath);

            // Set up the path to the annotation element that is a child of xs:all.
            allElementAnnotationPath = new XmlElementPath();
            allElementAnnotationPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
            allElementAnnotationPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
            allElementAnnotationPath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));
            allElementAnnotationPath.AddElement(new QualifiedName("all", namespaceURI, prefix));
            allElementAnnotationPath.AddElement(new QualifiedName("annotation", namespaceURI, prefix));

            // Get the xs:all annotation child element.
            allElementAnnotationChildElements = schemaCompletion.GetChildElementCompletion(allElementAnnotationPath);
        }
 public void Init()
 {
     completionItems = new XmlCompletionItemCollection();
 }
 public void SetUpFixture()
 {
     defaultSchema          = new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema());
     completionItems        = new XmlCompletionItemCollection(defaultSchema.GetRootElementCompletion());
     selectedCompletionItem = completionItems.SuggestedItem;
 }
 public void CollectionHasItemsReturnsFalseIfCollectionEmpty()
 {
     itemCollection = new XmlCompletionItemCollection();
     Assert.IsFalse(itemCollection.HasItems);
 }