public void SimpleFileName() { string fileName = @"C:\temp\foo.xml"; string expectedUri = "file:///C:/temp/foo.xml"; Assert.AreEqual(expectedUri, XmlSchemaCompletionProvider.GetUri(fileName)); }
/// <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, XmlSchemaCompletionProvider schemaCompletionData, string elementName) { QualifiedName qualifiedName = schemaCompletionData.CreateQualifiedName(name); XmlSchemaCompletionProvider 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 GoToSchemaDefinitionCommand() { try { //try to resolve the schema XmlSchemaCompletionProvider 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); } }
/// <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(XmlSchemaCompletionProvider 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. XmlSchemaCompletionProvider 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); }
/// <summary> /// Creates two schemas, one which references the other via an /// xs:include. Both schemas will exist in the same folder. /// </summary> /// <param name="mainSchema">The main schema's xml.</param> /// <param name="includedSchema">The included schema's xml.</param> internal static XmlSchemaCompletionProvider CreateSchemaCompletionDataObject(string mainSchema, string includedSchema) { if (!Directory.Exists(schemaPath)) { Directory.CreateDirectory(schemaPath); } CreateSchema(Path.Combine(schemaPath, mainSchemaFileName), mainSchema); CreateSchema(Path.Combine(schemaPath, includedSchemaFileName), includedSchema); // Parse schema. string schemaFileName = Path.Combine(schemaPath, mainSchemaFileName); string baseUri = XmlSchemaCompletionProvider.GetUri(schemaFileName); return(new XmlSchemaCompletionProvider(baseUri, schemaFileName)); }
public void FixtureInit() { XmlSchemaCompletionDataCollection items = new XmlSchemaCompletionDataCollection(); StringReader reader = new StringReader(GetSchema(firstNamespace)); XmlSchemaCompletionProvider schema = new XmlSchemaCompletionProvider(reader); items.Add(schema); reader = new StringReader(GetSchema(secondNamespace)); schema = new XmlSchemaCompletionProvider(reader); items.Add(schema); var builder = new XmlSchemaCompletionBuilder(DummyCompletionSource.Instance); items.GetNamespaceCompletionData(builder); namespaceCompletionData = new CompletionContext(builder.GetItems()); }
async Task Init() { if (schemaCompletionData != null) { return; } using (var reader = new StreamReader(ResourceManager.GetXhtmlStrictSchema(), true)) { schemaCompletionData = new XmlSchemaCompletionProvider(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 = await schemaCompletionData.GetAttributeCompletionDataAsync(DummyCompletionSource.Instance, h1Path, CancellationToken.None); }
/// <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(XmlSchemaCompletionProvider 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); }
void SetDefaultSchema() { var filename = DocumentContext.Name; if (filename == null) { return; } defaultSchemaCompletionData = XmlSchemaManager.GetSchemaCompletionDataForFileName(filename); if (defaultSchemaCompletionData != null) { inferredCompletionData = null; } else { QueueInference(); } defaultNamespacePrefix = XmlSchemaManager.GetNamespacePrefixForFileName(filename); }
async Task Init() { if (schemaCompletionData != null) { return; } using (var reader = new StreamReader(ResourceManager.GetXsdSchema(), true)) { schemaCompletionData = new XmlSchemaCompletionProvider(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)); IAsyncCompletionSource source = DummyCompletionSource.Instance; mixedAttributeValues = await schemaCompletionData.GetAttributeValueCompletionDataAsync(source, choicePath, "mixed", CancellationToken.None); choicePath.Elements.Add(new QualifiedName("choice", namespaceURI, prefix)); // Get choice element info. choiceAttributes = await schemaCompletionData.GetAttributeCompletionDataAsync(source, choicePath, CancellationToken.None); maxOccursAttributeValues = await schemaCompletionData.GetAttributeValueCompletionDataAsync(source, choicePath, "maxOccurs", CancellationToken.None); // Set up element path. elementPath = new XmlElementPath(); elementPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix)); elementFormDefaultAttributeValues = await schemaCompletionData.GetAttributeValueCompletionDataAsync(source, elementPath, "elementFormDefault", CancellationToken.None); blockDefaultAttributeValues = await schemaCompletionData.GetAttributeValueCompletionDataAsync(source, elementPath, "blockDefault", CancellationToken.None); finalDefaultAttributeValues = await schemaCompletionData.GetAttributeValueCompletionDataAsync(source, elementPath, "finalDefault", CancellationToken.None); elementPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix)); // Get element attribute info. elementAttributes = await schemaCompletionData.GetAttributeCompletionDataAsync(source, elementPath, CancellationToken.None); // 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 = await schemaCompletionData.GetChildElementCompletionDataAsync(source, simpleEnumPath, CancellationToken.None); // 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 = await schemaCompletionData.GetAttributeCompletionDataAsync(source, enumPath, CancellationToken.None); // 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 = await schemaCompletionData.GetChildElementCompletionDataAsync(source, allElementPath, CancellationToken.None); // 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 = await schemaCompletionData.GetChildElementCompletionDataAsync(source, allElementAnnotationPath, CancellationToken.None); }
public void EmptyString() { Assert.AreEqual(String.Empty, XmlSchemaCompletionProvider.GetUri(String.Empty)); }
public void NullFileName() { Assert.AreEqual(String.Empty, XmlSchemaCompletionProvider.GetUri(null)); }
public void FixtureInitBase() { schemaCompletionData = CreateSchemaCompletionDataObject(); FixtureInit(); }