Example #1
0
        /// <summary>
        /// Gets the autocomplete data for the specified attribute value.
        /// </summary>
        public ICompletionData[] GetAttributeValueCompletionData(XmlElementPath path, string name)
        {
            XmlCompletionDataCollection data = new XmlCompletionDataCollection();

            // Locate matching element.
            XmlSchemaElement element = FindElement(path);

            // Get completion data.
            if (element != null)
            {
                data = GetAttributeValueCompletionData(element, name);
            }

            return data.ToArray();
        }
Example #2
0
        /// <summary>
        /// Gets the child element completion data for the xml element that exists
        /// at the end of the specified path.
        /// </summary>
        public ICompletionData[] GetChildElementCompletionData(XmlElementPath path)
        {
            XmlCompletionDataCollection data = new XmlCompletionDataCollection();

            // Locate matching element.
            XmlSchemaElement element = FindElement(path);

            // Get completion data.
            if (element != null)
            {
                data = GetChildElementCompletionData(element, path.Elements.LastPrefix);
            }

            return data.ToArray();
        }
Example #3
0
 /// <summary>
 /// Finds the element that exists at the specified path.
 /// </summary>
 /// <remarks>This method is not used when generating completion data,
 /// but is a useful method when locating an element so we can jump
 /// to its schema definition.</remarks>
 /// <returns><see langword="null"/> if no element can be found.</returns>
 public XmlSchemaElement FindElement(XmlElementPath path)
 {
     XmlSchemaElement element = null;
     for (int i = 0; i < path.Elements.Count; ++i)
     {
         QualifiedName name = path.Elements[i];
         if (i == 0)
         {
             // Look for root element.
             element = FindElement(name);
             if (element == null)
             {
                 break;
             }
         }
         else
         {
             element = FindChildElement(element, name);
             if (element == null)
             {
                 break;
             }
         }
     }
     return element;
 }
Example #4
0
        /// <summary>
        /// Gets the attribute completion data for the xml element that exists
        /// at the end of the specified path.
        /// </summary>
        public ICompletionData[] GetAttributeCompletionData(XmlElementPath path)
        {
            XmlCompletionDataCollection data = new XmlCompletionDataCollection();

            // Locate matching element.
            XmlSchemaElement element = FindElement(path);

            // Get completion data.
            if (element != null)
            {
                prohibitedAttributes.Clear();
                data = GetAttributeCompletionData(element);
            }

            return data.ToArray();
        }
Example #5
0
        /// <summary>
        /// Gets the parent element path based on the index position. This
        /// method does not compact the path so it will include all elements
        /// including those in another namespace in the path.
        /// </summary>
        static XmlElementPath GetFullParentElementPath(string xml, QualifiedNameCollection namespaces)
        {
            XmlElementPath path = new XmlElementPath();
            IDictionary<string, string> namespacesInScope = null;
            using (StringReader reader = new StringReader(xml))
            {
                using (XmlTextReader xmlReader = new XmlTextReader(reader))
                {
                    try
                    {
                        xmlReader.XmlResolver = null; // prevent XmlTextReader from loading external DTDs
                        while (xmlReader.Read())
                        {
                            switch (xmlReader.NodeType)
                            {
                                case XmlNodeType.Element:
                                    if (!xmlReader.IsEmptyElement)
                                    {
                                        QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix);
                                        path.Elements.Add(elementName);
                                    }
                                    break;
                                case XmlNodeType.EndElement:
                                    path.Elements.RemoveLast();
                                    break;
                            }
                        }
                    }
                    catch (XmlException)
                    {
                        namespacesInScope = xmlReader.GetNamespacesInScope(XmlNamespaceScope.All);
                    }
                }
            }

            // Add namespaces in scope for the last element read.
            if (namespacesInScope != null)
            {
                foreach (KeyValuePair<string, string> ns in namespacesInScope)
                {
                    namespaces.Add(new QualifiedName(String.Empty, ns.Value, ns.Key));
                }
            }

            return path;
        }
Example #6
0
 /// <summary>
 /// Gets path of the xml element start tag that the specified
 /// <paramref name="index"/> is currently inside.
 /// </summary>
 /// <remarks>If the index outside the start tag then an empty path
 /// is returned.</remarks>
 /// <param name="index"></param>
 /// <param name="xml"></param>
 /// <param name="namespaces">Returns the namespaces that are
 /// exist in the xml.</param>
 static XmlElementPath GetActiveElementStartPath(string xml, int index, QualifiedNameCollection namespaces)
 {
     XmlElementPath path = new XmlElementPath();
     string elementText = GetActiveElementStartText(xml, index);
     if (elementText != null)
     {
         path = GetActiveElementStartPath(xml, index, elementText, namespaces);
     }
     return path;
 }
        ICompletionData[] GetChildElementCompletionData(XmlElementPath path)
        {
            ICompletionData[] completionData = null;

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

            return completionData;
        }
        ICompletionData[] GetAttributeValueCompletionData(XmlElementPath path, string name)
        {
            ICompletionData[] completionData = null;

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

            return completionData;
        }
        /// <summary>
        /// Finds the schema given the xml element path.
        /// </summary>
        public XmlSchemaCompletionData FindSchema(XmlElementPath path)
        {
            if (path.Elements.Count > 0)
            {
                string namespaceUri = path.Elements[0].Namespace;
                if (namespaceUri.Length > 0)
                {
                    return schemaCompletionDataItems[namespaceUri];
                }
                else if (defaultSchemaCompletionData != null)
                {

                    // Use the default schema namespace if none
                    // specified in a xml element path, otherwise
                    // we will not find any attribute or element matches
                    // later.
                    foreach (QualifiedName name in path.Elements)
                    {
                        if (name.Namespace.Length == 0)
                        {
                            name.Namespace = defaultSchemaCompletionData.NamespaceUri;
                        }
                    }
                    return defaultSchemaCompletionData;
                }
            }
            return null;
        }