本文整理汇总了C#中OpenXmlPart.GetXDocumentWithTracking方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlPart.GetXDocumentWithTracking方法的具体用法?C# OpenXmlPart.GetXDocumentWithTracking怎么用?C# OpenXmlPart.GetXDocumentWithTracking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlPart
的用法示例。
在下文中一共展示了OpenXmlPart.GetXDocumentWithTracking方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPartForUnsupportedContent
private static void TestPartForUnsupportedContent(OpenXmlPart part, int sourceNumber)
{
XNamespace[] obsoleteNamespaces = new[]
{
XNamespace.Get("http://schemas.microsoft.com/office/word/2007/5/30/wordml"),
XNamespace.Get("http://schemas.microsoft.com/office/word/2008/9/16/wordprocessingDrawing"),
XNamespace.Get("http://schemas.microsoft.com/office/word/2009/2/wordml"),
};
XDocument xDoc = part.GetXDocumentWithTracking();
XElement invalidElement = xDoc.Descendants()
.FirstOrDefault(d =>
{
bool b = d.Name == W.subDoc ||
d.Name == W.control ||
d.Name == W.altChunk ||
d.Name.LocalName == "contentPart" ||
obsoleteNamespaces.Contains(d.Name.Namespace);
bool b2 = b ||
d.Attributes().Any(a => obsoleteNamespaces.Contains(a.Name.Namespace));
return b2;
});
if (invalidElement != null)
{
if (invalidElement.Name == W.subDoc)
throw new DocumentBuilderException(String.Format("Source {0} is unsupported document - contains sub document",
sourceNumber));
if (invalidElement.Name == W.control)
throw new DocumentBuilderException(String.Format("Source {0} is unsupported document - contains ActiveX controls",
sourceNumber));
if (invalidElement.Name == W.altChunk)
throw new DocumentBuilderException(String.Format("Source {0} is unsupported document - contains altChunk",
sourceNumber));
if (invalidElement.Name.LocalName == "contentPart")
throw new DocumentBuilderException(String.Format("Source {0} is unsupported document - contains contentPart content",
sourceNumber));
if (obsoleteNamespaces.Contains(invalidElement.Name.Namespace) ||
invalidElement.Attributes().Any(a => obsoleteNamespaces.Contains(a.Name.Namespace)))
throw new DocumentBuilderException(String.Format("Source {0} is unsupported document - contains obsolete namespace",
sourceNumber));
}
}