本文整理汇总了C#中OpenXmlElement.IsInVersion方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlElement.IsInVersion方法的具体用法?C# OpenXmlElement.IsInVersion怎么用?C# OpenXmlElement.IsInVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlElement
的用法示例。
在下文中一共展示了OpenXmlElement.IsInVersion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetElementAction
internal ElementAction GetElementAction(OpenXmlElement element, FileFormatVersions format)
{
if (format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007) || format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007 | FileFormatVersions.Office2013))
{
return ElementAction.Normal;
}
if (element is AlternateContent)
{
return ElementAction.ACBlock;
}
if (element.IsInVersion(format))
{
return ElementAction.Normal;
}
if (IsIgnorableNs(element.NamespaceUri))
{
if (IsPreservedElement(element.NamespaceUri, element.LocalName))
{
return ElementAction.Normal;
}
if (IsProcessContent(element.NamespaceUri, element.LocalName))
{
return ElementAction.ProcessContent;
}
return ElementAction.Ignore;
}
return ElementAction.Normal;
}
示例2: GetChildMc
private static OpenXmlElement GetChildMc(this OpenXmlElement parent, OpenXmlElement child, MCContext mcContext, FileFormatVersions format)
{
// Use stack to cache the next siblings in different levels.
Stack<OpenXmlElement> nextSiblings = new Stack<OpenXmlElement>();
while (child != null)
{
var acb = child as AlternateContent;
if (acb == null && child.IsInVersion(format))
{
return child;
}
else
{
mcContext.PushMCAttributes2(child.MCAttributes, child.LookupNamespace);
if (acb != null)
{
nextSiblings.Push(child.GetNextNonMiscElementSibling());
var select = mcContext.GetContentFromACBlock(acb, format);
if (select != null)
{
child = select.GetFirstNonMiscElementChild();
}
else
{
// The ACB has no children elements.
// case like: <acb/> <acb><choice/><fallback/></acb>
child = null;
}
}
else
{
// Ignorable element, skip it
if (mcContext.IsIgnorableNs(child.NamespaceUri))
{
// Any element marked with ProcessContent should be an Ignorable Element
if (mcContext.IsProcessContent(child))
{
nextSiblings.Push(child.GetNextNonMiscElementSibling());
//
child = child.GetFirstNonMiscElementChild();
}
else
{
child = child.GetNextNonMiscElementSibling();
}
}
else
{
mcContext.PopMCAttributes2();
return child;
}
}
mcContext.PopMCAttributes2();
}
while (child == null && nextSiblings.Count > 0)
{
child = nextSiblings.Pop();
}
}
// child is null.
return child;
}
示例3: Validate
/// <summary>
/// Validates the specified element.
/// </summary>
/// <param name="openXmlElement">The target OpenXmlElement.</param>
/// <returns>A set of validation erros.</returns>
/// <exception cref="ArgumentNullException">Thrown when the "openXmlElement" parameter is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the "openXmlElement" is type of OpenXmlUnknownElement, OpenXmlMiscNode, AlternateContent, AlternateContentChoice or AlternateContentFallback.</exception>
/// <exception cref="InvalidOperationException">Thrown when the "openXmlElement" is not defined in the specified FileFormat.</exception>
public IEnumerable<ValidationErrorInfo> Validate(OpenXmlElement openXmlElement)
{
if (openXmlElement == null)
{
throw new ArgumentNullException("openXmlElement");
}
if (openXmlElement is OpenXmlUnknownElement)
{
throw new ArgumentOutOfRangeException("openXmlElement", ExceptionMessages.CannotValidateUnknownElement);
}
if (openXmlElement is OpenXmlMiscNode)
{
throw new ArgumentOutOfRangeException("openXmlElement", ExceptionMessages.CannotValidateMiscNode);
}
if (openXmlElement is AlternateContent ||
openXmlElement is AlternateContentChoice ||
openXmlElement is AlternateContentFallback)
{
throw new ArgumentOutOfRangeException("openXmlElement", ExceptionMessages.CannotValidateAcbElement);
}
if (! openXmlElement.IsInVersion(this.FileFormat))
{
switch (this.FileFormat)
{
case FileFormatVersions.Office2007:
throw new InvalidOperationException(ExceptionMessages.ElementIsNotInOffice2007);
case FileFormatVersions.Office2010:
throw new InvalidOperationException(ExceptionMessages.ElementIsNotInOffice2010);
case FileFormatVersions.Office2013:
throw new InvalidOperationException(ExceptionMessages.ElementIsNotInOffice2013);
}
}
// TODO: if the FileFormat is Office2007, and the element is only in Office2010 and O15.
// then this method should throw exceptions.
var validationResult = new ValidationResult();
validationResult.Valid = true;
validationResult.MaxNumberOfErrors = this._settings.MaxNumberOfErrors;
validationResult.MaxNumberOfErrorsEventHandler += this.SchemaValidator.OnCancel;
var validationContext = new ValidationContext();
// this.ValidationContext.Settings = new ValidationSettings(this.FileFormat, this.SchemaOnly);
validationContext.FileFormat = this.FileFormat;
validationContext.ValidationErrorEventHandler += validationResult.OnValidationError;
validationContext.Element = openXmlElement;
// Do NOT use "yield return" in this method, as "yield return" are deferred executed.
// Otherwise, the null check is not performed when the method is called, but rather, when the returned enumerator is moved for the first time.
// That means that the exception isn't thrown until possibly far, far away from the actual site of the error, which is potentially confusing.
this.SchemaValidator.Validate(validationContext);
validationContext.Element = openXmlElement;
this.FullSemanticValidator.Validate(validationContext);
return this.YieldResult(validationResult);
}