示例#1
0
        /// <summary>
        /// Gets a collection of defined prefix-namespace mappings that are currently in scope.
        /// </summary>
        public IDictionary <string, string> GetNamespacesInScope(XmlNamespaceScope scope)
        {
            var result = new Dictionary <string, string>();

            if (scope == XmlNamespaceScope.All)
            {
                result["xml"] = XmlNamespace;
                //result["xmlns"] = XmlnsNamespace; xmlns should not be included in GetNamespacesInScope() results
            }
            for (AXmlElement current = this; current != null; current = current.Parent as AXmlElement)
            {
                foreach (var attr in current.Attributes)
                {
                    if (attr.Name.StartsWith("xmlns:", StringComparison.Ordinal))
                    {
                        string prefix = attr.LocalName;
                        if (!result.ContainsKey(prefix))
                        {
                            result.Add(prefix, attr.Value);
                        }
                    }
                    else if (attr.Name == "xmlns" && !result.ContainsKey(string.Empty))
                    {
                        result.Add(string.Empty, attr.Value);
                    }
                }
                if (scope == XmlNamespaceScope.Local)
                {
                    break;
                }
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Gets the prefix that is mapped to the specified namespace URI.
        /// </summary>
        /// <returns>The prefix that is mapped to the namespace URI; null if the namespace URI is not mapped to a prefix.</returns>
        public string LookupPrefix(string namespaceName)
        {
            if (namespaceName == null)
            {
                throw new ArgumentNullException("namespaceName");
            }

            if (namespaceName == XmlNamespace)
            {
                return("xml");
            }
            if (namespaceName == XmlnsNamespace)
            {
                return("xmlns");
            }
            for (AXmlElement current = this; current != null; current = current.Parent as AXmlElement)
            {
                foreach (var attr in current.Attributes)
                {
                    if (attr.Value == namespaceName)
                    {
                        if (attr.Name.StartsWith("xmlns:", StringComparison.Ordinal))
                        {
                            return(attr.LocalName);
                        }
                        else if (attr.Name == "xmlns")
                        {
                            return(string.Empty);
                        }
                    }
                }
            }
            return(null);            // Can not find prefix
        }
示例#3
0
        /// <summary>
        /// Recursively resolve given prefix in this context.
        /// </summary>
        /// <returns><c>null</c> if prefix is not found</returns>
        public string LookupNamespace(string prefix)
        {
            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }

            // Implicit namespaces
            if (prefix == "xml")
            {
                return(XmlNamespace);
            }
            if (prefix == "xmlns")
            {
                return(XmlnsNamespace);
            }

            string lookFor = (prefix.Length > 0 ? "xmlns:" + prefix : "xmlns");

            for (AXmlElement current = this; current != null; current = current.Parent as AXmlElement)
            {
                foreach (var attr in current.Attributes)
                {
                    if (attr.Name == lookFor)
                    {
                        return(attr.Value);
                    }
                }
            }
            return(null);            // Can not find prefix
        }
 /// <summary> Visit AXmlElement </summary>
 public virtual void VisitElement(AXmlElement element)
 {
     foreach (AXmlObject child in element.Children)
     {
         child.AcceptVisitor(this);
     }
 }
		/// <summary>
		/// Creates a new documentation element.
		/// </summary>
        public XmlDocumentationElement(AXmlElement element, ISymbol declaringEntity)
		{
			if (element == null)
				throw new ArgumentNullException("element");
			this.element = element;
			this.xmlObject = element;
			this.declaringEntity = declaringEntity;
		}
 /// <summary>
 /// Creates a new documentation element.
 /// </summary>
 public XmlDocumentationElement(AXmlElement element, ISymbol declaringEntity)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     this.element         = element;
     this.xmlObject       = element;
     this.declaringEntity = declaringEntity;
 }
        static List <XmlDocumentationElement> CreateElements(IEnumerable <AXmlObject> childObjects, ISymbol declaringEntity, int nestingLevel)
        {
            List <XmlDocumentationElement> list = new List <XmlDocumentationElement>();

            foreach (var child in childObjects)
            {
                var childText    = child as AXmlText;
                var childTag     = child as AXmlTag;
                var childElement = child as AXmlElement;
                if (childText != null)
                {
                    list.Add(new XmlDocumentationElement(childText.Value, declaringEntity));
                }
                else if (childTag != null && childTag.IsCData)
                {
                    foreach (var text in childTag.Children.OfType <AXmlText>())
                    {
                        list.Add(new XmlDocumentationElement(text.Value, declaringEntity));
                    }
                }
                else if (childElement != null)
                {
                    if (nestingLevel < 5 && childElement.Name == "inheritdoc")
                    {
                        string  cref                   = childElement.GetAttributeValue("cref");
                        ISymbol inheritedFrom          = null;
                        string  inheritedDocumentation = null;
                        if (cref != null)
                        {
                            //inheritedFrom = crefResolver(cref);
                            //if (inheritedFrom != null)
                            //    inheritedDocumentation = inheritedFrom.GetDocumentationCommentXml();
                        }
                        else
                        {
                            //                     foreach (var baseMember in InheritanceHelper.GetBaseMembers((IMember)declaringEntity, includeImplementedInterfaces: true)) {
                            //	inheritedDocumentation = baseMember.Documentation;
                            //	if (inheritedDocumentation != null) {
                            //		inheritedFrom = baseMember;
                            //		break;
                            //	}
                            //}
                        }

                        if (inheritedDocumentation != null)
                        {
                            var doc = new AXmlParser().Parse(SourceText.From(inheritedDocumentation));

                            // XPath filter not yet implemented
                            if (childElement.Parent is AXmlDocument && childElement.GetAttributeValue("select") == null)
                            {
                                // Inheriting documentation at the root level
                                List <string> doNotInherit = new List <string>();
                                doNotInherit.Add("overloads");
                                doNotInherit.AddRange(childObjects.OfType <AXmlElement>().Select(e => e.Name).Intersect(
                                                          doNotInheritIfAlreadyPresent));

                                var inheritedChildren = doc.Children.Where(
                                    inheritedObject => {
                                    AXmlElement inheritedElement = inheritedObject as AXmlElement;
                                    return(!(inheritedElement != null && doNotInherit.Contains(inheritedElement.Name)));
                                });

                                list.AddRange(CreateElements(inheritedChildren, inheritedFrom, nestingLevel + 1));
                            }
                        }
                    }
                    else
                    {
                        list.Add(new XmlDocumentationElement(childElement, declaringEntity)
                        {
                            nestingLevel = nestingLevel
                        });
                    }
                }
            }
            if (list.Count > 0 && list[0].IsTextNode)
            {
                if (string.IsNullOrWhiteSpace(list[0].textContent))
                {
                    list.RemoveAt(0);
                }
                else
                {
                    list[0].textContent = list[0].textContent.TrimStart();
                }
            }
            if (list.Count > 0 && list[list.Count - 1].IsTextNode)
            {
                if (string.IsNullOrWhiteSpace(list[list.Count - 1].textContent))
                {
                    list.RemoveAt(list.Count - 1);
                }
                else
                {
                    list[list.Count - 1].textContent = list[list.Count - 1].textContent.TrimEnd();
                }
            }
            return(list);
        }
		/// <summary> Visit AXmlElement </summary>
		public virtual void VisitElement(AXmlElement element)
		{
			foreach (AXmlObject child in element.Children)
				child.AcceptVisitor(this);
		}