Esempio n. 1
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>
        public static XmlElementPath GetActiveElementStartPath(string xml, int index)
        {
            XmlElementPath path = new XmlElementPath();

            string elementText = GetActiveElementStartText(xml, index);

            if (elementText != null)
            {
                QualifiedName elementName      = GetElementName(elementText);
                NamespaceURI  elementNamespace = GetElementNamespace(elementText);

                path = GetParentElementPath(xml.Substring(0, index));
                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 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. 3
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = 0;
         if (NamespaceURI != null)
         {
             hashCode = NamespaceURI.GetHashCode();
         }
         if (LocalName != null)
         {
             hashCode = (hashCode * 397) ^ LocalName.GetHashCode();
         }
         return(hashCode);
     }
 }
        /// <summary>
        /// Gets the element namespace from the element start tag
        /// string.
        /// </summary>
        /// <param name="xml">This string must start at the
        /// element we are interested in.</param>
        private static NamespaceURI GetElementNamespace(string xml)
        {
            NamespaceURI namespaceURI = new NamespaceURI();

            Match match = Regex.Match(xml, ".*?(xmlns\\s*?|xmlns:.*?)=\\s*?['\\\"](.*?)['\\\"]");

            if (match.Success)
            {
                namespaceURI.Namespace = match.Groups[2].Value;

                string xmlns       = match.Groups[1].Value.Trim();
                int    prefixIndex = xmlns.IndexOf(':');
                if (prefixIndex > 0)
                {
                    namespaceURI.Prefix = xmlns.Substring(prefixIndex + 1);
                }
            }

            return(namespaceURI);
        }
Esempio n. 5
0
		/// <summary>
		/// Gets the element namespace from the element start tag
		/// string.
		/// </summary>
		/// <param name="xml">This string must start at the
		/// element we are interested in.</param>
		static NamespaceURI GetElementNamespace(string xml)
		{
			NamespaceURI namespaceURI = new NamespaceURI();
			
			Match match = Regex.Match(xml, ".*?(xmlns\\s*?|xmlns:.*?)=\\s*?['\\\"](.*?)['\\\"]");
			if (match.Success) {
				namespaceURI.Namespace = match.Groups[2].Value;
				
				string xmlns = match.Groups[1].Value.Trim();
				int prefixIndex = xmlns.IndexOf(':');
				if (prefixIndex > 0) {
					namespaceURI.Prefix = xmlns.Substring(prefixIndex + 1);
				}
			}
			
			return namespaceURI;
		}
Esempio n. 6
0
 public override int GetHashCode()
 {
     return((NamespaceURI?.GetHashCode() ?? 0) + (LocalName?.GetHashCode() ?? 0));
 }