本文整理汇总了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);
}
示例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;
}