当前位置: 首页>>代码示例>>C#>>正文


C# XDocument.Annotation方法代码示例

本文整理汇总了C#中System.Xml.Linq.XDocument.Annotation方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.Annotation方法的具体用法?C# XDocument.Annotation怎么用?C# XDocument.Annotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XDocument的用法示例。


在下文中一共展示了XDocument.Annotation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Wrap

        /// <summary>
        /// Wrap an existing <see cref="XDocument"/> as an <see cref="XdmNode"/>. This is the <see cref="XDocument"/>
        /// equivalent of <see cref="DocumentBuilder.Wrap(XmlDocument)"/>.
        /// </summary>
        /// <remarks>
        /// PoC:
        /// 
        /// Creates wrapper objects for all nodes in the document graph and stores them using 
        /// <see cref="XObject.AddAnnotation(object)"/>. Will throw if any node has already been wrapped.
        /// 
        /// Idealy this would be an extension to <see cref="DocumentBuilder"/>, but DocumentBuilder does not expose
        /// its Configuration object publically.
        /// </remarks>
        public static XdmNode Wrap(this Processor processor, XDocument doc)
        {
            if (doc.Annotation<XObjectWrapper>() != null)
                throw new InvalidOperationException("XDocument is already annotated with a wrapper.");
            var docWrapper = (XDocumentWrapper)XObjectWrapper.MakeWrapper(doc);
            docWrapper.setConfiguration(processor.Implementation);
            doc.AddAnnotation(docWrapper);
            foreach (var node in doc.DescendantNodes())
            {
                if (node.Annotation<XObjectWrapper>() != null)
                    throw new InvalidOperationException(string.Format("{0} is already annotated with a wrapper.", node.GetType().Name));

                node.AddAnnotation(XObjectWrapper.MakeWrapper(node));

                if (node.NodeType == XmlNodeType.Element)
                {
                    foreach (var attr in ((XElement)node).Attributes())
                    {
                        if (attr.Annotation<XObjectWrapper>() != null)
                            throw new InvalidOperationException("Attribute is already annotated with a wrapper.");

                        attr.AddAnnotation(XObjectWrapper.MakeWrapper(attr));
                    }
                }
            }

            return (XdmNode)XdmValue.Wrap(docWrapper);
        }
开发者ID:zanyants,项目名称:saxon-xdoc,代码行数:41,代码来源:ProcessorExtensions.cs

示例2: GetDefaultParagraphStyleName

        private static string GetDefaultParagraphStyleName(XDocument stylesXDoc)
        {
            XElement defaultParagraphStyle;
            string defaultParagraphStyleName = null;

            StylesInfo stylesInfo = stylesXDoc.Annotation<StylesInfo>();

            if (stylesInfo != null)
                defaultParagraphStyleName = stylesInfo.DefaultParagraphStyleName;
            else
            {
                defaultParagraphStyle = stylesXDoc
                    .Root
                    .Elements(W.style)
                    .FirstOrDefault(s =>
                    {
                        if ((string)s.Attribute(W.type) != "paragraph")
                            return false;
                        var defaultAttribute = s.Attribute(W._default);
                        var isDefault = false;
                        if (defaultAttribute != null &&
                            (bool)s.Attribute(W._default).ToBoolean())
                            isDefault = true;
                        return isDefault;
                    });
                defaultParagraphStyleName = null;
                if (defaultParagraphStyle != null)
                    defaultParagraphStyleName = (string)defaultParagraphStyle.Attribute(W.styleId);
                stylesInfo = new StylesInfo()
                {
                    DefaultParagraphStyleName = defaultParagraphStyleName,
                };
                stylesXDoc.AddAnnotation(stylesInfo);
            }
            return defaultParagraphStyleName;
        }
开发者ID:bbqchickenrobot,项目名称:OpenXmlPowerTools,代码行数:36,代码来源:ListItemRetriever.cs


注:本文中的System.Xml.Linq.XDocument.Annotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。