Esempio n. 1
0
        /// <summary>
        /// Gets the active element path given the element text.
        /// </summary>
        static XmlElementPath GetActiveElementStartPath(string xml, int index, string elementText, QualifiedNameCollection namespaces)
        {
            QualifiedName elementName = GetElementName(elementText);

            if (elementName == null)
            {
                return(new XmlElementPath());
            }

            NamespaceURI elementNamespace = GetElementNamespace(elementText);

            XmlElementPath path = GetFullParentElementPath(xml.Substring(0, index), namespaces);

            // Try to get a namespace for the active element's prefix.
            if (elementName.Prefix.Length > 0 && elementNamespace.Namespace.Length == 0)
            {
                elementName.Namespace      = GetNamespaceForPrefix(namespaces, elementName.Prefix);
                elementNamespace.Namespace = elementName.Namespace;
                elementNamespace.Prefix    = elementName.Prefix;
            }

            if (elementNamespace.Namespace.Length == 0)
            {
                if (path.Elements.Count > 0)
                {
                    QualifiedName parentName = path.Elements[path.Elements.Count - 1];
                    elementNamespace.Namespace = parentName.Namespace;
                    elementNamespace.Prefix    = parentName.Prefix;
                }
            }
            path.Elements.Add(new QualifiedName(elementName.Name, elementNamespace.Namespace, elementNamespace.Prefix));
            path.Compact();
            return(path);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the parent element path based on the index position.
        /// </summary>
        public static XmlElementPath GetParentElementPath(string xml)
        {
            QualifiedNameCollection namespaces = new QualifiedNameCollection();
            XmlElementPath          path       = GetFullParentElementPath(xml, namespaces);

            path.Compact();
            return(path);
        }
Esempio n. 3
0
        public XmlCompletionItemCollection GetAttributeValueCompletion(XmlElementPath path, string attributeName, XmlSchemaCompletion defaultSchema)
        {
            path.Compact();
            XmlCompletionItemCollection items = new XmlCompletionItemCollection();

            foreach (XmlSchemaCompletion schema in GetSchemas(path, defaultSchema))
            {
                items.AddRange(schema.GetAttributeValueCompletion(path, attributeName));
            }
            return(items);
        }
Esempio n. 4
0
 public XmlCompletionItemCollection GetAttributeCompletion(string textUpToCursor, XmlSchemaCompletion defaultSchema)
 {
     if (!XmlParser.IsInsideAttributeValue(textUpToCursor, textUpToCursor.Length))
     {
         XmlElementPath path = XmlParser.GetActiveElementStartPath(textUpToCursor, textUpToCursor.Length);
         path.Compact();
         if (path.Elements.HasItems)
         {
             return(GetAttributeCompletion(path, defaultSchema));
         }
     }
     return(new XmlCompletionItemCollection());
 }