public XmlCompletionDataProvider(XmlSchemaCompletionDataCollection schemaCompletionDataItems, XmlSchemaCompletionData defaultSchemaCompletionData, string defaultNamespacePrefix) { this.schemaCompletionDataItems = schemaCompletionDataItems; this.defaultSchemaCompletionData = defaultSchemaCompletionData; this.defaultNamespacePrefix = defaultNamespacePrefix; DefaultIndex = 0; }
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]; }
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); }
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("type=\"dir\"/>"); index = xml.IndexOf("dir", index); schemaSimpleType = (XmlSchemaSimpleType)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); }
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=\"coreattrs\""); index = xml.IndexOf("coreattrs", index); schemaAttributeGroup = (XmlSchemaAttributeGroup)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData); }
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(); }
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=\"xs:list"); index = xml.IndexOf("xs", index); referencedSchemaElement = (XmlSchemaElement)XmlView.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); }
public void SetUpFixture() { Form parentForm = new Form(); parentForm.CreateControl(); XmlSchemaCompletionData schema = new XmlSchemaCompletionData(ResourceManager.GetXhtmlStrictSchema()); XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); schemas.Add(schema); provider = new XmlCompletionDataProvider(schemas, schema, String.Empty); TextEditorControl textEditor = new TextEditorControl(); completionDataItems = provider.GenerateCompletionData(@"C:\Test.xml", textEditor.ActiveTextAreaControl.TextArea, '<'); using (CodeCompletionWindow completionWindow = CodeCompletionWindow.ShowCompletionWindow(parentForm, textEditor, @"C:\Test.xml", provider, '<')) { CodeCompletionListView listView = (CodeCompletionListView)completionWindow.Controls[0]; selectedCompletionData = listView.SelectedCompletionData; completionWindow.Close(); } }
public void Init() { treeViewContainer = new DerivedXmlTreeViewContainerControl(); XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); XmlSchemaCompletionData xhtmlSchema = new XmlSchemaCompletionData(reader); XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xhtmlSchema, String.Empty); treeViewContainer.LoadXml("<html><body></body></html>", provider); doc = treeViewContainer.Document; treeView = treeViewContainer.TreeView; htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[0]; htmlTreeNode.Expanding(); bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0]; bodyElement = (XmlElement)doc.SelectSingleNode("/html/body"); }
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"]; }
/// <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> static XmlSchemaObject FindSchemaObjectType(string name, XmlCompletionDataProvider provider, XmlSchemaCompletionData schemaCompletionData, string elementName) { QualifiedName qualifiedName = schemaCompletionData.CreateQualifiedName(name); XmlSchemaCompletionData qualifiedNameSchema = provider.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; }
/// <summary> /// Gets the XmlSchemaObject that defines the currently selected xml element or /// attribute. /// </summary> /// <param name="text">The complete xml text.</param> /// <param name="index">The current cursor index.</param> /// <param name="provider">The completion data provider</param> /// <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 static XmlSchemaObject GetSchemaObjectSelected(string xml, int index, XmlCompletionDataProvider provider, XmlSchemaCompletionData currentSchemaCompletionData) { // Find element under cursor. XmlElementPath path = XmlParser.GetActiveElementStartPathAtIndex(xml, index); string attributeName = XmlParser.GetAttributeNameAtIndex(xml, index); // Find schema definition object. XmlSchemaCompletionData schemaCompletionData = provider.FindSchema(path); XmlSchemaObject schemaObject = null; if (schemaCompletionData != null) { XmlSchemaElement element = schemaCompletionData.FindElement(path); schemaObject = element; if (element != null) { if (attributeName.Length > 0) { XmlSchemaAttribute attribute = schemaCompletionData.FindAttribute(element, attributeName); if (attribute != null) { if (currentSchemaCompletionData != null) { schemaObject = GetSchemaObjectReferenced(xml, index, provider, currentSchemaCompletionData, element, attribute); } else { schemaObject = attribute; } } } return schemaObject; } } return null; }
public void FixtureInitBase() { schemaCompletionData = CreateSchemaCompletionDataObject(); FixtureInit(); }
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); }
/// <summary> /// Gets a value indicating whether the /// <see cref='XmlSchemaCompletionDataCollection'/> contains the specified <see cref='XmlSchemaCompletionData'/>. /// </summary> /// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to locate.</param> /// <returns> /// <see langword='true'/> if the <see cref='XmlSchemaCompletionData'/> is contained in the collection; /// otherwise, <see langword='false'/>. /// </returns> /// <seealso cref='XmlSchemaCompletionDataCollection.IndexOf'/> public bool Contains(XmlSchemaCompletionData val) { return List.Contains(val); }
/// <summary> /// Adds a <see cref='XmlSchemaCompletionData'/> with the specified value to the /// <see cref='XmlSchemaCompletionDataCollection'/>. /// </summary> /// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to add.</param> /// <returns>The index at which the new element was inserted.</returns> /// <seealso cref='XmlSchemaCompletionDataCollection.AddRange'/> public int Add(XmlSchemaCompletionData val) { return List.Add(val); }
/// <summary> /// Adds the schema to the user schemas folder and makes the /// schema available to the xml editor. /// </summary> public static void AddUserSchema(XmlSchemaCompletionData schemaData) { if (SchemaCompletionDataItems[schemaData.NamespaceUri] == null) { if (!Directory.Exists(UserSchemaFolder)) { Directory.CreateDirectory(UserSchemaFolder); } string fileName = Path.GetFileName(schemaData.FileName); string destinationFileName = Path.Combine(UserSchemaFolder, fileName); File.Copy(schemaData.FileName, destinationFileName); schemaData.FileName = destinationFileName; SchemaCompletionDataItems.Add(schemaData); OnUserSchemaAdded(); } else { LoggingService.Warn("Trying to add a schema that already exists. Namespace=" + schemaData.NamespaceUri); } }
/// <summary> /// Removes a specific <see cref='XmlSchemaCompletionData'/> from the <see cref='XmlSchemaCompletionDataCollection'/>. /// </summary> /// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to remove from the <see cref='XmlSchemaCompletionDataCollection'/>.</param> /// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception> public void Remove(XmlSchemaCompletionData val) { List.Remove(val); }
/// <summary> /// Initializes a new instance of <see cref='XmlSchemaCompletionDataCollection'/> containing any array of <see cref='XmlSchemaCompletionData'/> objects. /// </summary> /// <param name='val'> /// A array of <see cref='XmlSchemaCompletionData'/> objects with which to intialize the collection /// </param> public XmlSchemaCompletionDataCollection(XmlSchemaCompletionData[] val) { this.AddRange(val); }
/// <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; }
/// <summary> /// Returns the index of a <see cref='XmlSchemaCompletionData'/> in /// the <see cref='XmlSchemaCompletionDataCollection'/>. /// </summary> /// <param name='val'>The <see cref='XmlSchemaCompletionData'/> to locate.</param> /// <returns> /// The index of the <see cref='XmlSchemaCompletionData'/> of <paramref name='val'/> in the /// <see cref='XmlSchemaCompletionDataCollection'/>, if found; otherwise, -1. /// </returns> /// <seealso cref='XmlSchemaCompletionDataCollection.Contains'/> public int IndexOf(XmlSchemaCompletionData val) { return List.IndexOf(val); }
/// <summary> /// Copies the <see cref='XmlSchemaCompletionDataCollection'/> 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='XmlSchemaCompletionDataCollection'/>.</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='XmlSchemaCompletionDataCollection'/> 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(XmlSchemaCompletionData[] array, int index) { List.CopyTo(array, index); }
/// <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> static XmlSchemaObject GetSchemaObjectReferenced(string xml, int index, XmlCompletionDataProvider provider, XmlSchemaCompletionData currentSchemaCompletionData, XmlSchemaElement element, XmlSchemaAttribute attribute) { XmlSchemaObject schemaObject = null; if (IsXmlSchemaNamespace(element)) { // Find attribute value. string attributeValue = XmlParser.GetAttributeValueAtIndex(xml, index); if (attributeValue.Length == 0) { return attribute; } if (attribute.Name == "ref") { schemaObject = FindSchemaObjectReference(attributeValue, provider, currentSchemaCompletionData, element.Name); } else if (attribute.Name == "type") { schemaObject = FindSchemaObjectType(attributeValue, provider, currentSchemaCompletionData, element.Name); } } if (schemaObject != null) { return schemaObject; } return attribute; }
/// <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> 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. LoggingService.Warn("Ignoring duplicate schema namespace " + data.NamespaceUri); } } else { // Namespace is null. LoggingService.Warn("Ignoring schema with no namespace " + data.FileName); } } catch (Exception ex) { LoggingService.Warn("Unable to read schema '" + fileName + "'. ", ex); } }
/// <summary> /// Inserts a <see cref='XmlSchemaCompletionData'/> into the <see cref='XmlSchemaCompletionDataCollection'/> 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='XmlSchemaCompletionData'/> to insert.</param> /// <seealso cref='XmlSchemaCompletionDataCollection.Add'/> public void Insert(int index, XmlSchemaCompletionData val) { List.Insert(index, val); }
/// <summary> /// Copies the elements of an array to the end of the <see cref='XmlSchemaCompletionDataCollection'/>. /// </summary> /// <param name='val'> /// An array of type <see cref='XmlSchemaCompletionData'/> containing the objects to add to the collection. /// </param> /// <seealso cref='XmlSchemaCompletionDataCollection.Add'/> public void AddRange(XmlSchemaCompletionData[] val) { for (int i = 0; i < val.Length; i++) { this.Add(val[i]); } }