Example #1
0
        void RemoveRegisteredSchema(XmlSchemaCompletionData schema)
        {
            if (addedSchemas.Contains(schema) && !schema.ReadOnly)
            {
                addedSchemas.Remove(schema);
            }
            else
            {
                removedSchemas.Add(schema);
            }

            TreeIter iter;
            bool     valid = registeredSchemasStore.GetIterFirst(out iter);

            while (valid)
            {
                if (GetRegisteredSchema(iter) == schema)
                {
                    registeredSchemasStore.Remove(ref iter);
                    break;
                }
                valid = registeredSchemasStore.IterNext(ref iter);
            }

            //restore built-in schema
            if (!schema.ReadOnly)
            {
                XmlSchemaCompletionData builtin = XmlSchemaManager.BuiltinSchemas[schema.NamespaceUri];
                if (builtin != null)
                {
                    AppendSchemaToStore(builtin);
                }
            }
        }
Example #2
0
        public void SimpleFileName()
        {
            string fileName    = @"C:\temp\foo.xml";
            string expectedUri = "file:///C:/temp/foo.xml";

            Assert.AreEqual(expectedUri, XmlSchemaCompletionData.GetUri(fileName));
        }
        /// <summary>
        /// If the attribute value found references another item in the schema
        /// return this instead of the attribute schema object. For example, if the
        /// user can select the attribute value and the code will work out the schema object pointed to by the ref
        /// or type attribute:
        ///
        /// xs:element ref="ref-name"
        /// xs:attribute type="type-name"
        /// </summary>
        /// <returns>
        /// The <paramref name="attribute"/> if no schema object was referenced.
        /// </returns>
        XmlSchemaObject GetSchemaObjectReferenced(XmlSchemaCompletionData currentSchemaCompletionData, XmlSchemaElement element, XmlSchemaAttribute attribute)
        {
            XmlSchemaObject schemaObject = null;

            if (IsXmlSchemaNamespace(element))
            {
                // Find attribute value.
                //fixme implement
                string attributeValue = "";                // XmlParser.GetAttributeValueAtIndex(xml, index);
                if (attributeValue.Length == 0)
                {
                    return(attribute);
                }

                if (attribute.Name == "ref")
                {
                    schemaObject = FindSchemaObjectReference(attributeValue, currentSchemaCompletionData, element.Name);
                }
                else if (attribute.Name == "type")
                {
                    schemaObject = FindSchemaObjectType(attributeValue, currentSchemaCompletionData, element.Name);
                }
            }

            if (schemaObject != null)
            {
                return(schemaObject);
            }
            return(attribute);
        }
        /// <summary>
        /// Attempts to locate the reference name in the specified schema.
        /// </summary>
        /// <param name="name">The reference to look up.</param>
        /// <param name="schemaCompletionData">The schema completion data to use to
        /// find the reference.</param>
        /// <param name="elementName">The element to determine what sort of reference it is
        /// (e.g. group, attribute, element).</param>
        /// <returns><see langword="null"/> if no match can be found.</returns>
        XmlSchemaObject FindSchemaObjectReference(string name, XmlSchemaCompletionData schemaCompletionData, string elementName)
        {
            QualifiedName           qualifiedName       = schemaCompletionData.CreateQualifiedName(name);
            XmlSchemaCompletionData qualifiedNameSchema = FindSchema(qualifiedName.Namespace);

            if (qualifiedNameSchema != null)
            {
                schemaCompletionData = qualifiedNameSchema;
            }
            switch (elementName)
            {
            case "element":
                return(schemaCompletionData.FindElement(qualifiedName));

            case "attribute":
                return(schemaCompletionData.FindAttribute(qualifiedName.Name));

            case "group":
                return(schemaCompletionData.FindGroup(qualifiedName.Name));

            case "attributeGroup":
                return(schemaCompletionData.FindAttributeGroup(qualifiedName.Name));
            }
            return(null);
        }
        public void GoToSchemaDefinitionCommand()
        {
            try {
                //try to resolve the schema

                XmlSchemaCompletionData currentSchemaCompletionData = FindSchemaFromFileName(FileName);

                XmlSchemaObject schemaObject = GetSchemaObjectSelected(currentSchemaCompletionData);



                // Open schema if resolved

                if (schemaObject != null && schemaObject.SourceUri != null && schemaObject.SourceUri.Length > 0)
                {
                    string schemaFileName = schemaObject.SourceUri.Replace("file:/", String.Empty);
                    IdeApp.Workbench.OpenDocument(
                        schemaFileName,
                        DocumentContext.Project,
                        Math.Max(1, schemaObject.LineNumber),
                        Math.Max(1, schemaObject.LinePosition));
                }
            } catch (Exception ex) {
                MonoDevelop.Core.LoggingService.LogError("Could not open document.", ex);
                MessageService.ShowError("Could not open document.", ex);
            }
        }
Example #6
0
 public XmlCompletionDataProvider(XmlSchemaCompletionDataCollection schemaCompletionDataItems, XmlSchemaCompletionData defaultSchemaCompletionData, string defaultNamespacePrefix)
 {
     this.schemaCompletionDataItems   = schemaCompletionDataItems;
     this.defaultSchemaCompletionData = defaultSchemaCompletionData;
     this.defaultNamespacePrefix      = defaultNamespacePrefix;
     DefaultIndex = 0;
 }
Example #7
0
 /// <summary>
 /// Reads an individual schema and adds it to the collection.
 /// </summary>
 /// <remarks>
 /// If the schema namespace exists in the collection it is not added.
 /// </remarks>
 public void ReadSchema(string fileName, bool readOnly)
 {
     try
     {
         string baseUri = XmlSchemaCompletionData.GetUri(fileName);
         XmlSchemaCompletionData data = new XmlSchemaCompletionData(baseUri, fileName);
         if (data.NamespaceUri != null)
         {
             if (schemas[data.NamespaceUri] == null)
             {
                 data.ReadOnly = readOnly;
                 schemas.Add(data);
             }
             else
             {
                 // Namespace already exists.
                 Debug.WriteLine("Ignoring duplicate schema namespace " + data.NamespaceUri);
             }
         }
         else
         {
             Debug.WriteLine("Ignoring schema with no namespace " + data.FileName);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Unable to read schema '" + fileName + "'. ", ex);
     }
 }
        /// <summary>
        /// Attempts to locate the type name in the specified schema.
        /// </summary>
        /// <param name="name">The type to look up.</param>
        /// <param name="schemaCompletionData">The schema completion data to use to
        /// find the type.</param>
        /// <param name="elementName">The element to determine what sort of type it is
        /// (e.g. group, attribute, element).</param>
        /// <returns><see langword="null"/> if no match can be found.</returns>
        XmlSchemaObject FindSchemaObjectType(string name, XmlSchemaCompletionData schemaCompletionData, string elementName)

        {
            QualifiedName qualifiedName = schemaCompletionData.CreateQualifiedName(name);

            XmlSchemaCompletionData qualifiedNameSchema = FindSchema(qualifiedName.Namespace);

            if (qualifiedNameSchema != null)
            {
                schemaCompletionData = qualifiedNameSchema;
            }

            switch (elementName)
            {
            case "element":

                return(schemaCompletionData.FindComplexType(qualifiedName));

            case "attribute":

                return(schemaCompletionData.FindSimpleType(qualifiedName.Name));
            }

            return(null);
        }
        public void Init()
        {
            treeViewContainer = new XmlTreeViewContainerControl();

            XmlTextReader                     reader      = ResourceManager.GetXhtmlStrictSchema();
            XmlSchemaCompletionData           xhtmlSchema = new XmlSchemaCompletionData(reader);
            XmlSchemaCompletionDataCollection schemas     = new XmlSchemaCompletionDataCollection();
            XmlCompletionDataProvider         provider    = new XmlCompletionDataProvider(schemas, xhtmlSchema, String.Empty);

            treeViewContainer.LoadXml("<!-- comment --><html><body class='a'><p>Text</p></body></html>", provider);
            doc      = treeViewContainer.Document;
            treeView = treeViewContainer.TreeView;

            commentTreeNode = (XmlCommentTreeNode)treeView.Nodes[0];
            htmlTreeNode    = (XmlElementTreeNode)treeView.Nodes[1];
            htmlTreeNode.Expanding();

            bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0];
            bodyTreeNode.Expanding();

            paraTreeNode = (XmlElementTreeNode)bodyTreeNode.Nodes[0];
            paraTreeNode.Expanding();

            textTreeNode = (XmlTextTreeNode)paraTreeNode.Nodes[0];
        }
Example #10
0
        public void Init()
        {
            treeViewContainer = new DerivedXmlTreeViewContainerControl();
            treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged;

            XmlTextReader                     reader      = ResourceManager.GetXhtmlStrictSchema();
            XmlSchemaCompletionData           xhtmlSchema = new XmlSchemaCompletionData(reader);
            XmlSchemaCompletionDataCollection schemas     = new XmlSchemaCompletionDataCollection();

            provider = new XmlCompletionDataProvider(schemas, xhtmlSchema, String.Empty);

            treeViewContainer.LoadXml("<html id='a'>text<body></body></html>", provider);
            doc      = treeViewContainer.Document;
            treeView = treeViewContainer.TreeView;

            htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[0];
            htmlTreeNode.Expanding();
            textTreeNode = (XmlTextTreeNode)htmlTreeNode.Nodes[0];

            splitContainer = (SplitContainer)treeViewContainer.Controls["splitContainer"];

            textBox             = (RichTextBox)splitContainer.Panel2.Controls["textBox"];
            errorMessageTextBox = (RichTextBox)splitContainer.Panel2.Controls["errorMessageTextBox"];
            attributesGrid      = (PropertyGrid)splitContainer.Panel2.Controls["attributesGrid"];
        }
Example #11
0
        /// <summary>

        /// Gets the XmlSchemaObject that defines the currently selected xml element or attribute.

        /// </summary>

        /// <param name="currentSchemaCompletionData">This is the schema completion data for the schema currently being
        /// displayed. This can be null if the document is not a schema.</param>

        public XmlSchemaObject GetSchemaObjectSelected(XmlSchemaCompletionData currentSchemaCompletionData)

        {
            // Find element under cursor.

            XmlElementPath path = GetElementPath();

            //attribute name under cursor, if valid

            string     attributeName = null;
            XAttribute xatt          = Tracker.Engine.Nodes.Peek(0) as XAttribute;

            if (xatt != null)
            {
                XName xattName = xatt.Name;
                if (Tracker.Engine.CurrentState is XmlNameState)
                {
                    xattName = GetCompleteName();
                }
                attributeName = xattName.FullName;
            }


            // Find schema definition object.

            XmlSchemaCompletionData schemaCompletionData = FindSchema(path);

            XmlSchemaObject schemaObject = null;

            if (schemaCompletionData != null)
            {
                XmlSchemaElement element = schemaCompletionData.FindElement(path);

                schemaObject = element;

                if (element != null)
                {
                    if (!string.IsNullOrEmpty(attributeName))
                    {
                        XmlSchemaAttribute attribute = schemaCompletionData.FindAttribute(element, attributeName);

                        if (attribute != null)
                        {
                            if (currentSchemaCompletionData != null)
                            {
                                schemaObject = GetSchemaObjectReferenced(currentSchemaCompletionData, element, attribute);
                            }
                            else
                            {
                                schemaObject = attribute;
                            }
                        }
                    }

                    return(schemaObject);
                }
            }

            return(null);
        }
Example #12
0
        /// <summary>
        /// Loads the specified schema and adds it to an internal collection.
        /// </summary>
        /// <remarks>The schema file is not copied to the user's schema folder
        /// until they click the OK button.</remarks>
        /// <returns><see langword="true"/> if the schema namespace
        /// does not already exist; otherwise <see langword="false"/>
        /// </returns>
        bool AddSchema(string fileName)
        {
            // Load the schema.
            XmlSchemaCompletionData schema = new XmlSchemaCompletionData(fileName);

            // Make sure the schema has a target namespace.
            if (schema.NamespaceUri == null)
            {
                MessageService.ShowErrorFormatted("${res:ICSharpCode.XmlEditor.XmlSchemasPanel.NoTargetNamespace}", Path.GetFileName(schema.FileName));
                return(false);
            }

            // Check that the schema does not exist.
            if (SchemaNamespaceExists(schema.NamespaceUri))
            {
                MessageService.ShowErrorFormatted("${res:ICSharpCode.XmlEditor.XmlSchemasPanel.NamespaceExists}", schema.NamespaceUri);
                return(false);
            }

            // Store the schema so we can add it later.
            int index = schemaListBox.Items.Add(new XmlSchemaListBoxItem(schema.NamespaceUri));

            schemaListBox.SelectedIndex = index;
            addedSchemas.Add(schema);
            if (removedSchemaNamespaces.Contains(schema.NamespaceUri))
            {
                removedSchemaNamespaces.Remove(schema.NamespaceUri);
            }

            return(true);
        }
Example #13
0
        /// <summary>
        /// Reads an individual schema and adds it to the collection.
        /// </summary>
        /// <remarks>
        /// If the schema namespace exists in the collection it is not added.
        /// </remarks>
        static void LoadSchema(List <XmlSchemaCompletionData> list, string fileName, bool readOnly)
        {
            try {
                string baseUri = XmlSchemaCompletionData.GetUri(fileName);
                XmlSchemaCompletionData data = new XmlSchemaCompletionData(baseUri, fileName);

                if (data.NamespaceUri == null)
                {
                    LoggingService.LogWarning(
                        "XmlSchemaManager is ignoring schema with no namespace, from file '{0}'.",
                        data.FileName);
                    return;
                }

                foreach (XmlSchemaCompletionData d in list)
                {
                    if (d.NamespaceUri == data.NamespaceUri)
                    {
                        LoggingService.LogWarning(
                            "XmlSchemaManager is ignoring schema with duplicate namespace '{0}'.",
                            data.NamespaceUri);
                        return;
                    }
                }

                data.ReadOnly = readOnly;
                list.Add(data);
            } catch (Exception ex) {
                LoggingService.LogWarning(
                    "XmlSchemaManager is unable to read schema '{0}', because of the following error: {1}",
                    fileName, ex.Message);
            }
        }
Example #14
0
        protected virtual void addRegisteredSchema(object sender, EventArgs args)
        {
            string fileName = XmlEditorService.BrowseForSchemaFile();

            // We need to present the window so that the keyboard focus returns to the correct parent window
            ((Gtk.Window)Toplevel).Present();

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            string shortName = System.IO.Path.GetFileName(fileName);

            //load the schema
            XmlSchemaCompletionData schema = null;

            try {
                schema = new XmlSchemaCompletionData(fileName);
            } catch (Exception ex) {
                string msg = GettextCatalog.GetString("Schema '{0}' could not be loaded.", shortName);
                MessageService.ShowError(msg, ex);
                return;
            }

            // Make sure the schema has a target namespace.
            if (schema.NamespaceUri == null)
            {
                MessageService.ShowError(
                    GettextCatalog.GetString("Schema '{0}' has no target namespace.", shortName));
                return;
            }

            //if namaspace conflict, ask user whether they want to replace existing schema
            XmlSchemaCompletionData oldSchema = GetRegisteredSchema(schema.NamespaceUri);

            if (oldSchema != null)
            {
                bool replace = MessageService.Confirm(
                    GettextCatalog.GetString(
                        "A schema is already registered with the namespace '{0}'. Would you like to replace it?",
                        schema.NamespaceUri),
                    new AlertButton(GettextCatalog.GetString("Replace"))
                    );
                if (!replace)
                {
                    return;
                }

                //remove the old schema
                RemoveRegisteredSchema(oldSchema);
            }

            // Store the schema so we can add it for real later, if the "ok" button's clicked
            TreeIter newIter = AddRegisteredSchema(schema);

            registeredSchemasView.Selection.SelectIter(newIter);
            ScrollToSelection(registeredSchemasView);
        }
		public void SetUpFixture()
		{
			schemas = new XmlSchemaCompletionDataCollection();
			XmlSchemaCompletionData completionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());
			expectedNamespace = completionData.NamespaceUri;
			completionData.FileName = @"/home/Schemas/MySchema.xsd";
			schemas.Add(completionData);
			
			provider = new XmlCompletionDataProvider(schemas, completionData, String.Empty, null);
		}
Example #16
0
        public void SetUpFixture()
        {
            schemas = new XmlSchemaCompletionDataCollection();
            XmlSchemaCompletionData completionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());

            expectedNamespace       = completionData.NamespaceUri;
            completionData.FileName = @"C:\Schemas\MySchema.xsd";
            schemas.Add(completionData);

            provider = new XmlCompletionDataProvider(schemas, completionData, String.Empty);
        }
Example #17
0
        protected virtual void removeRegisteredSchema(object sender, System.EventArgs e)
        {
            XmlSchemaCompletionData schema = GetSelectedSchema();

            if (schema == null)
            {
                throw new InvalidOperationException("Should not be able to activate removeRegisteredSchema button while no row is selected.");
            }

            RemoveRegisteredSchema(schema);
        }
		public override void FixtureInit()
		{
			XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
			schemas.Add(SchemaCompletionData);
			XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());
			schemas.Add(xsdSchemaCompletionData);
			XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty, null);

			string xml = GetSchema();
			int index = xml.IndexOf("type=\"dir\"/>");
			index = xml.IndexOf("dir", index);
			schemaSimpleType = (XmlSchemaSimpleType)XmlEditorView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
		}
        private ICompletionData[] GetChildElementCompletionData(XmlElementPath path)
        {
            ICompletionData[] completionData = null;

            XmlSchemaCompletionData schema = FindSchema(path);

            if (schema != null)
            {
                completionData = schema.GetChildElementCompletionData(path);
            }

            return(completionData);
        }
		public void FixtureInit()
		{
			XmlSchemaCompletionDataCollection items = new XmlSchemaCompletionDataCollection();
			
			StringReader reader = new StringReader(GetSchema(firstNamespace));
			XmlSchemaCompletionData schema = new XmlSchemaCompletionData(reader);
			items.Add(schema);
			
			reader = new StringReader(GetSchema(secondNamespace));
			schema = new XmlSchemaCompletionData(reader);
			items.Add(schema);
			namespaceCompletionData = items.GetNamespaceCompletionData();
		}
        ICompletionData[] GetAttributeCompletionData(XmlElementPath path)
        {
            ICompletionData[] completionData = null;

            XmlSchemaCompletionData schema = FindSchema(path);

            if (schema != null)
            {
                completionData = schema.GetAttributeCompletionData(path);
            }

            return(completionData);
        }
		public override void FixtureInit()
		{
			XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
			schemas.Add(SchemaCompletionData);
			XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());
			schemas.Add(xsdSchemaCompletionData);
			XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty, null);
			
			string xml = GetSchema();			
			int index = xml.IndexOf("ref=\"coreattrs\"");
			index = xml.IndexOf("coreattrs", index);
			schemaAttributeGroup = (XmlSchemaAttributeGroup)XmlEditorView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
		}
        ICompletionData[] GetAttributeValueCompletionData(XmlElementPath path, string name)
        {
            ICompletionData[] completionData = null;

            XmlSchemaCompletionData schema = defaultSchemaCompletionData;

            if (schema != null)
            {
                completionData = schema.GetAttributeValueCompletionData(path, name);
            }

            return(completionData);
        }
Example #24
0
        TreeIter AddRegisteredSchema(XmlSchemaCompletionData schema)
        {
            if (removedSchemas.Contains(schema))
            {
                removedSchemas.Remove(schema);
            }
            else
            {
                addedSchemas.Add(schema);
            }

            return(AppendSchemaToStore(schema));
        }
        ICompletionData[] GetChildElementCompletionData(XmlElementPath path)
        {
            ICompletionData[] completionData = null;

            XmlSchemaCompletionData schema = defaultSchemaCompletionData;

            if (schema != null)
            {
                completionData = schema.GetChildElementCompletionData(path);
            }

            return(completionData);
        }
Example #26
0
        public void FixtureInit()
        {
            XmlSchemaCompletionDataCollection items = new XmlSchemaCompletionDataCollection();

            StringReader            reader = new StringReader(GetSchema(firstNamespace));
            XmlSchemaCompletionData schema = new XmlSchemaCompletionData(reader);

            items.Add(schema);

            reader = new StringReader(GetSchema(secondNamespace));
            schema = new XmlSchemaCompletionData(reader);
            items.Add(schema);
            namespaceCompletionData = new CompletionDataList(items.GetNamespaceCompletionData());
        }
        /// <summary>
        /// Removes the schema with the specified namespace from the
        /// user schemas folder and removes the completion data.
        /// </summary>
        public void RemoveUserSchema(string namespaceUri)
        {
            XmlSchemaCompletionData schemaData = SchemaCompletionDataItems[namespaceUri];

            if (schemaData != null)
            {
                if (File.Exists(schemaData.FileName))
                {
                    File.Delete(schemaData.FileName);
                }
                SchemaCompletionDataItems.Remove(schemaData);
                OnUserSchemaRemoved();
            }
        }
Example #28
0
		public void FixtureInit()
		{
			XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema();
			schemaCompletionData = new XmlSchemaCompletionData(reader);
			
			// Set up h1 element's path.
			h1Path = new XmlElementPath();
			h1Path.Elements.Add(new QualifiedName("html", namespaceURI));
			h1Path.Elements.Add(new QualifiedName("body", namespaceURI));
			h1Path.Elements.Add(new QualifiedName("h1", namespaceURI));
			
			// Get h1 element info.
			h1Attributes = schemaCompletionData.GetAttributeCompletionData(h1Path);
		}
		public override void FixtureInit()
		{
			XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
			schemas.Add(SchemaCompletionData);
			XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());
			schemas.Add(xsdSchemaCompletionData);
			XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty, null);
			
			string xml = GetSchema();
			
			int index = xml.IndexOf("ref=\"xs:list");
			index = xml.IndexOf("xs", index);
			referencedSchemaElement = (XmlSchemaElement)XmlEditorView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
		}
		public void FixtureInit()
		{
			XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema();
			schemaCompletionData = new XmlSchemaCompletionData(reader);
			
			// Set up h1 element's path.
			h1Path = new XmlElementPath();
			h1Path.Elements.Add(new QualifiedName("html", namespaceURI));
			h1Path.Elements.Add(new QualifiedName("body", namespaceURI));
			h1Path.Elements.Add(new QualifiedName("h1", namespaceURI));
			
			// Get h1 element info.
			h1Attributes = schemaCompletionData.GetAttributeCompletionData(h1Path);
		}
Example #31
0
        /// <summary>
        /// Schedules the schema for removal.
        /// </summary>
        void RemoveSchema(string namespaceUri)
        {
            RemoveListBoxItem(namespaceUri);

            XmlSchemaCompletionData addedSchema = addedSchemas[namespaceUri];

            if (addedSchema != null)
            {
                addedSchemas.Remove(addedSchema);
            }
            else
            {
                removedSchemaNamespaces.Add(namespaceUri);
            }
        }
Example #32
0
        /// <summary>
        /// Gets the schema completion data that is associated with the
        /// specified file extension.
        /// </summary>
        public static XmlSchemaCompletionData GetSchemaCompletionData(string extension)
        {
            XmlSchemaCompletionData data = null;

            XmlSchemaAssociation association = XmlEditorAddInOptions.GetSchemaAssociation(extension);

            if (association != null)
            {
                if (association.NamespaceUri.Length > 0)
                {
                    data = SchemaCompletionDataItems[association.NamespaceUri];
                }
            }
            return(data);
        }
Example #33
0
        XmlSchemaCompletionData GetItem(string namespaceUri)
        {
            XmlSchemaCompletionData matchedItem = null;

            foreach (XmlSchemaCompletionData item in this)
            {
                if (item.NamespaceUri == namespaceUri)
                {
                    matchedItem = item;
                    break;
                }
            }

            return(matchedItem);
        }
        /// <summary>
        /// Gets the schema completion data that is associated with the
        /// specified file extension.
        /// </summary>
        internal XmlSchemaCompletionData GetSchemaCompletionData(string extension)
        {
            XmlSchemaCompletionData data = null;

            XmlSchemaAssociation association = GetSchemaAssociation(extension);

            if (association != null)
            {
                if (association.NamespaceUri.Length > 0)
                {
                    data = SchemaCompletionDataItems[association.NamespaceUri];
                }
            }
            return(data);
        }
Example #35
0
        /// <summary>
        /// Removes the schema with the specified namespace from the
        /// user schemas folder and removes the completion data.
        /// </summary>
        public static void RemoveUserSchema(string namespaceUri)
        {
            XmlSchemaCompletionData schemaData = UserSchemas [namespaceUri];

            if (schemaData != null)
            {
                if (File.Exists(schemaData.FileName))
                {
                    File.Delete(schemaData.FileName);
                }
                UserSchemas.Remove(schemaData);
                schemaSetTask = null;
                OnUserSchemaRemoved();
            }
        }
Example #36
0
        public override void FixtureInit()
        {
            XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();

            schemas.Add(SchemaCompletionData);
            XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());

            schemas.Add(xsdSchemaCompletionData);
            XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty);

            string xml   = GetSchema();
            int    index = xml.IndexOf("ref=\"dir\"");

            index           = xml.IndexOf("dir", index);
            schemaAttribute = (XmlSchemaAttribute)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
        }
		public void FixtureInit()
		{
			XmlTextReader reader = ResourceManager.GetXsdSchema();
			schemaCompletionData = new XmlSchemaCompletionData(reader);
			
			// Set up choice element's path.
			choicePath = new XmlElementPath();
			choicePath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix));
			choicePath.Elements.Add(new QualifiedName("element", namespaceURI, prefix));
			choicePath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix));
			
			mixedAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(choicePath, "mixed");

			choicePath.Elements.Add(new QualifiedName("choice", namespaceURI, prefix));
			
			// Get choice element info.
			choiceAttributes = schemaCompletionData.GetAttributeCompletionData(choicePath);
			maxOccursAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(choicePath, "maxOccurs");
			
			// Set up element path.
			elementPath = new XmlElementPath();
			elementPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix));
			
			elementFormDefaultAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(elementPath, "elementFormDefault");
			blockDefaultAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(elementPath, "blockDefault");
			finalDefaultAttributeValues = schemaCompletionData.GetAttributeValueCompletionData(elementPath, "finalDefault");
			
			elementPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix));
				
			// Get element attribute info.
			elementAttributes = schemaCompletionData.GetAttributeCompletionData(elementPath);

			// Set up simple enum type path.
			simpleEnumPath = new XmlElementPath();
			simpleEnumPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix));
			simpleEnumPath.Elements.Add(new QualifiedName("simpleType", namespaceURI, prefix));
			simpleEnumPath.Elements.Add(new QualifiedName("restriction", namespaceURI, prefix));
			
			// Get child elements.
			simpleEnumElements = schemaCompletionData.GetChildElementCompletionData(simpleEnumPath);

			// Set up enum path.
			enumPath = new XmlElementPath();
			enumPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix));
			enumPath.Elements.Add(new QualifiedName("simpleType", namespaceURI, prefix));
			enumPath.Elements.Add(new QualifiedName("restriction", namespaceURI, prefix));
			enumPath.Elements.Add(new QualifiedName("enumeration", namespaceURI, prefix));
			
			// Get attributes.
			enumAttributes = schemaCompletionData.GetAttributeCompletionData(enumPath);
			
			// Set up xs:all path.
			allElementPath = new XmlElementPath();
			allElementPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix));
			allElementPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix));
			allElementPath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix));
			allElementPath.Elements.Add(new QualifiedName("all", namespaceURI, prefix));
		
			// Get child elements of the xs:all element.
			allElementChildElements = schemaCompletionData.GetChildElementCompletionData(allElementPath);
			
			// Set up the path to the annotation element that is a child of xs:all.
			allElementAnnotationPath = new XmlElementPath();
			allElementAnnotationPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix));
			allElementAnnotationPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix));
			allElementAnnotationPath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix));
			allElementAnnotationPath.Elements.Add(new QualifiedName("all", namespaceURI, prefix));
			allElementAnnotationPath.Elements.Add(new QualifiedName("annotation", namespaceURI, prefix));
			
			// Get the xs:all annotation child element.
			allElementAnnotationChildElements = schemaCompletionData.GetChildElementCompletionData(allElementAnnotationPath);
		}
		public void FixtureInitBase()
		{
			schemaCompletionData = CreateSchemaCompletionDataObject();
			FixtureInit();
		}