void GetChildElementCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaComplexType complexType, string prefix)
        {
            if (complexType.Particle is XmlSchemaSequence sequence)
            {
                GetChildElementCompletionData(data, sequence.Items, prefix);
                return;
            }
            if (complexType.Particle is XmlSchemaChoice choice)
            {
                GetChildElementCompletionData(data, choice.Items, prefix);
                return;
            }
            var complexContent = complexType.ContentModel as XmlSchemaComplexContent;

            if (complexContent != null)
            {
                GetChildElementCompletionData(data, complexContent, prefix);
                return;
            }
            var groupRef = complexType.Particle as XmlSchemaGroupRef;

            if (groupRef != null)
            {
                GetChildElementCompletionData(data, groupRef, prefix);
                return;
            }
            var all = complexType.Particle as XmlSchemaAll;

            if (all != null)
            {
                GetChildElementCompletionData(data, all.Items, prefix);
                return;
            }
        }
Ejemplo n.º 2
0
 public void GetNamespaceCompletionData(XmlSchemaCompletionBuilder builder)
 {
     foreach (XmlSchemaCompletionProvider schema in this)
     {
         builder.AddNamespace(schema.NamespaceUri);
     }
 }
        void GetChildElementCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaComplexContentRestriction restriction, string prefix)
        {
            if (restriction.Particle == null)
            {
                return;
            }
            var sequence = restriction.Particle as XmlSchemaSequence;

            if (sequence != null)
            {
                GetChildElementCompletionData(data, sequence.Items, prefix);
                return;
            }
            var choice = restriction.Particle as XmlSchemaChoice;

            if (choice != null)
            {
                GetChildElementCompletionData(data, choice.Items, prefix);
                return;
            }
            var groupRef = restriction.Particle as XmlSchemaGroupRef;

            if (groupRef != null)
            {
                GetChildElementCompletionData(data, groupRef, prefix);
                return;
            }
        }
 /// <summary>
 /// Gets the set of attribute values for an xs:boolean type.
 /// </summary>
 void GetBooleanAttributeValueCompletionData(XmlSchemaCompletionBuilder data)
 {
     data.AddAttributeValue("0");
     data.AddAttributeValue("1");
     data.AddAttributeValue("true");
     data.AddAttributeValue("false");
 }
        void GetAttributeCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaComplexType complexType)
        {
            GetAttributeCompletionData(data, complexType.Attributes);

            // Add any complex content attributes.
            var complexContent = complexType.ContentModel as XmlSchemaComplexContent;

            if (complexContent != null)
            {
                var extension   = complexContent.Content as XmlSchemaComplexContentExtension;
                var restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
                if (extension != null)
                {
                    GetAttributeCompletionData(data, extension);
                }
                else if (restriction != null)
                {
                    GetAttributeCompletionData(data, restriction);
                }
            }
            else
            {
                var simpleContent = complexType.ContentModel as XmlSchemaSimpleContent;
                if (simpleContent != null)
                {
                    GetAttributeCompletionData(data, simpleContent);
                }
            }
        }
 void GetAttributeCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaObjectCollection attributes)
 {
     foreach (XmlSchemaObject schemaObject in attributes)
     {
         var attribute = schemaObject as XmlSchemaAttribute;
         if (attribute != null)
         {
             if (!IsProhibitedAttribute(attribute))
             {
                 data.AddAttribute(attribute);
             }
             else
             {
                 prohibitedAttributes.Add(attribute);
             }
         }
         else
         {
             var attributeGroupRef = schemaObject as XmlSchemaAttributeGroupRef;
             if (attributeGroupRef != null)
             {
                 GetAttributeCompletionData(data, attributeGroupRef);
             }
         }
     }
 }
        void GetChildElementCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaElement element, string prefix)
        {
            var complexType = GetElementAsComplexType(element);

            if (complexType != null)
            {
                GetChildElementCompletionData(data, complexType, prefix);
            }
        }
        void GetAttributeCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaElement element)
        {
            var complexType = GetElementAsComplexType(element);

            if (complexType != null)
            {
                GetAttributeCompletionData(data, complexType);
            }
        }
        void GetAttributeCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaSimpleContent simpleContent)
        {
            var extension = simpleContent.Content as XmlSchemaSimpleContentExtension;

            if (extension != null)
            {
                GetAttributeCompletionData(data, extension);
            }
        }
        /// <summary>
        /// Gets attribute completion data from a group ref.
        /// </summary>
        void GetAttributeCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaAttributeGroupRef groupRef)
        {
            var group = FindAttributeGroup(schema, groupRef.RefName.Name);

            if (group != null)
            {
                GetAttributeCompletionData(data, group.Attributes);
            }
        }
        void GetAttributeCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaComplexContentExtension extension)
        {
            GetAttributeCompletionData(data, extension.Attributes);
            var baseComplexType = FindNamedType(schema, extension.BaseTypeName);

            if (baseComplexType != null)
            {
                GetAttributeCompletionData(data, baseComplexType);
            }
        }
 /// <summary>
 /// Adds any elements that have the specified substitution group.
 /// </summary>
 void AddSubstitionGroupElements(XmlSchemaCompletionBuilder data, XmlQualifiedName group, string prefix)
 {
     foreach (XmlSchemaElement element in schema.Elements.Values)
     {
         if (element.SubstitutionGroup == group)
         {
             data.AddElement(element.Name, prefix, element.Annotation);
         }
     }
 }
 void GetAttributeValueCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaSimpleTypeUnion union)
 {
     foreach (XmlSchemaObject schemaObject in union.BaseTypes)
     {
         var simpleType = schemaObject as XmlSchemaSimpleType;
         if (simpleType != null)
         {
             GetAttributeValueCompletionData(data, simpleType);
         }
     }
 }
 void GetChildElementCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaObjectCollection items, string prefix)
 {
     foreach (XmlSchemaObject schemaObject in items)
     {
         var childElement = schemaObject as XmlSchemaElement;
         if (childElement != null)
         {
             string name = childElement.Name;
             if (name == null)
             {
                 name = childElement.RefName.Name;
                 var element = FindElement(childElement.RefName);
                 if (element != null)
                 {
                     if (element.IsAbstract)
                     {
                         AddSubstitionGroupElements(data, element.QualifiedName, prefix);
                     }
                     else
                     {
                         data.AddElement(name, prefix, element.Annotation);
                     }
                 }
                 else
                 {
                     data.AddElement(name, prefix, childElement.Annotation);
                 }
             }
             else
             {
                 data.AddElement(name, prefix, childElement.Annotation);
             }
             continue;
         }
         var childSequence = schemaObject as XmlSchemaSequence;
         if (childSequence != null)
         {
             GetChildElementCompletionData(data, childSequence.Items, prefix);
             continue;
         }
         var childChoice = schemaObject as XmlSchemaChoice;
         if (childChoice != null)
         {
             GetChildElementCompletionData(data, childChoice.Items, prefix);
             continue;
         }
         var groupRef = schemaObject as XmlSchemaGroupRef;
         if (groupRef != null)
         {
             GetChildElementCompletionData(data, groupRef, prefix);
             continue;
         }
     }
 }
 void GetAttributeValueCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaSimpleTypeRestriction simpleTypeRestriction)
 {
     foreach (XmlSchemaObject schemaObject in simpleTypeRestriction.Facets)
     {
         var enumFacet = schemaObject as XmlSchemaEnumerationFacet;
         if (enumFacet != null)
         {
             data.AddAttributeValue(enumFacet.Value, enumFacet.Annotation);
         }
     }
 }
        void GetAttributeValueCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaElement element, string name)
        {
            var complexType = GetElementAsComplexType(element);

            if (complexType != null)
            {
                var attribute = FindAttribute(complexType, name);
                if (attribute != null)
                {
                    GetAttributeValueCompletionData(data, attribute);
                }
            }
        }
        public async Task <CompletionContext> GetAttributeValueCompletionDataAsync(IAsyncCompletionSource source, string tagName, string name, CancellationToken token)
        {
            await EnsureLoadedAsync();

            var list    = new XmlSchemaCompletionBuilder(source);
            var element = FindElement(tagName);

            if (element != null)
            {
                GetAttributeValueCompletionData(list, element, name);
            }
            return(new CompletionContext(list.GetItems()));
        }
        /// <summary>
        /// Gets the autocomplete data for the specified attribute value.
        /// </summary>
        public async Task <CompletionContext> GetAttributeValueCompletionDataAsync(IAsyncCompletionSource source, XmlElementPath path, string name, CancellationToken token)
        {
            await EnsureLoadedAsync();

            var builder = new XmlSchemaCompletionBuilder(source, path.Namespaces);
            var element = FindElement(path);

            if (element != null)
            {
                GetAttributeValueCompletionData(builder, element, name);
            }
            return(new CompletionContext(builder.GetItems()));
        }
        /// <summary>
        /// Gets the child element completion data for the xml element that exists
        /// at the end of the specified path.
        /// </summary>
        public async Task <CompletionContext> GetChildElementCompletionDataAsync(IAsyncCompletionSource source, XmlElementPath path, CancellationToken token)
        {
            await EnsureLoadedAsync();

            var builder = new XmlSchemaCompletionBuilder(source, path.Namespaces);
            var element = FindElement(path);

            if (element != null)
            {
                var last = path.Elements.LastOrDefault();
                GetChildElementCompletionData(builder, element, last != null ? last.Prefix : "");
            }
            return(new CompletionContext(builder.GetItems()));
        }
 void GetAttributeValueCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaSimpleTypeList list)
 {
     if (list.ItemType != null)
     {
         GetAttributeValueCompletionData(data, list.ItemType);
     }
     else if (list.ItemTypeName != null)
     {
         var simpleType = FindSimpleType(list.ItemTypeName);
         if (simpleType != null)
         {
             GetAttributeValueCompletionData(data, simpleType);
         }
     }
 }
        void GetChildElementCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaComplexContent complexContent, string prefix)
        {
            var extension = complexContent.Content as XmlSchemaComplexContentExtension;

            if (extension != null)
            {
                GetChildElementCompletionData(data, extension, prefix);
                return;
            }
            var restriction = complexContent.Content as XmlSchemaComplexContentRestriction;

            if (restriction != null)
            {
                GetChildElementCompletionData(data, restriction, prefix);
                return;
            }
        }
        /// <summary>
        /// Gets the possible root elements for an xml document using this schema.
        /// </summary>
        public async Task <CompletionContext> GetElementCompletionDataAsync(IAsyncCompletionSource source, string namespacePrefix, CancellationToken token)
        {
            await EnsureLoadedAsync();

            var builder = new XmlSchemaCompletionBuilder(source);

            foreach (XmlSchemaElement element in schema.Elements.Values)
            {
                if (element.Name != null)
                {
                    builder.AddElement(element.Name, namespacePrefix, element.Annotation);
                }
                else
                {
                    // Do not add reference element.
                }
            }
            return(new CompletionContext(builder.GetItems()));
        }
 void GetAttributeValueCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaAttribute attribute)
 {
     if (attribute.SchemaType != null)
     {
         var simpleTypeRestriction = attribute.SchemaType.Content as XmlSchemaSimpleTypeRestriction;
         if (simpleTypeRestriction != null)
         {
             GetAttributeValueCompletionData(data, simpleTypeRestriction);
         }
     }
     else if (attribute.AttributeSchemaType != null)
     {
         if (attribute.AttributeSchemaType.TypeCode == XmlTypeCode.Boolean)
         {
             GetBooleanAttributeValueCompletionData(data);
         }
         else
         {
             GetAttributeValueCompletionData(data, attribute.AttributeSchemaType);
         }
     }
 }
        void GetChildElementCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaGroupRef groupRef, string prefix)
        {
            var group = FindGroup(groupRef.RefName.Name);

            if (group == null)
            {
                return;
            }
            var sequence = group.Particle as XmlSchemaSequence;

            if (sequence != null)
            {
                GetChildElementCompletionData(data, sequence.Items, prefix);
                return;
            }
            var choice = group.Particle as XmlSchemaChoice;

            if (choice != null)
            {
                GetChildElementCompletionData(data, choice.Items, prefix);
                return;
            }
        }
        void GetAttributeValueCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaSimpleType simpleType)
        {
            var xsstr = simpleType.Content as XmlSchemaSimpleTypeRestriction;

            if (xsstr != null)
            {
                GetAttributeValueCompletionData(data, xsstr);
                return;
            }
            var xsstu = simpleType.Content as XmlSchemaSimpleTypeUnion;

            if (xsstu != null)
            {
                GetAttributeValueCompletionData(data, xsstu);
                return;
            }
            var xsstl = simpleType.Content as XmlSchemaSimpleTypeList;

            if (xsstl != null)
            {
                GetAttributeValueCompletionData(data, xsstl);
                return;
            }
        }
        void GetChildElementCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaComplexContentExtension extension, string prefix)
        {
            var complexType = FindNamedType(schema, extension.BaseTypeName);

            if (complexType != null)
            {
                GetChildElementCompletionData(data, complexType, prefix);
            }

            if (extension.Particle == null)
            {
                return;
            }

            var sequence = extension.Particle as XmlSchemaSequence;

            if (sequence != null)
            {
                GetChildElementCompletionData(data, sequence.Items, prefix);
                return;
            }
            var choice = extension.Particle as XmlSchemaChoice;

            if (choice != null)
            {
                GetChildElementCompletionData(data, choice.Items, prefix);
                return;
            }
            var groupRef = extension.Particle as XmlSchemaGroupRef;

            if (groupRef != null)
            {
                GetChildElementCompletionData(data, groupRef, prefix);
                return;
            }
        }
 void GetAttributeCompletionData(XmlSchemaCompletionBuilder data, XmlSchemaSimpleContentExtension extension)
 {
     GetAttributeCompletionData(data, extension.Attributes);
 }