本文整理汇总了C#中Run.AddNamespaceDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C# Run.AddNamespaceDeclaration方法的具体用法?C# Run.AddNamespaceDeclaration怎么用?C# Run.AddNamespaceDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Run
的用法示例。
在下文中一共展示了Run.AddNamespaceDeclaration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompatibilityRuleAttributesValidationTest
public void CompatibilityRuleAttributesValidationTest()
{
var validator = new SchemaValidator();
var element = new Paragraph();
var run = new Run();
element.AppendChild(run);
var result = validator.Validate(element);
Assert.True(result.Valid);
element.AddNamespaceDeclaration("o15", "http://o15.com");
result = validator.Validate(element);
Assert.True(result.Valid);
run.MCAttributes = new MarkupCompatibilityAttributes();
run.MCAttributes.Ignorable = "o15";
result = validator.Validate(element);
Assert.True(result.Valid);
run.AddNamespaceDeclaration("w15", "http://w15.com");
result = validator.Validate(element);
Assert.True(result.Valid);
run.MCAttributes.Ignorable = "o15 w15";
result = validator.Validate(element);
Assert.True(result.Valid);
run.MCAttributes.PreserveAttributes = " o15:id w15:*";
run.MCAttributes.PreserveElements = "o15:* w15:* ";
run.MCAttributes.ProcessContent = " o15:newE w15:newW ";
result = validator.Validate(element);
Assert.True(result.Valid);
run.MCAttributes.PreserveElements = "x15:* ";
result = validator.Validate(element);
Assert.False(result.Valid);
Assert.Equal(1, result.Errors.Count);
Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
Assert.Equal("MC_InvalidPreserveElementsAttribute", result.Errors[0].Id);
run.MCAttributes.Ignorable = null;
run.MCAttributes.PreserveAttributes = null;
run.MCAttributes.PreserveElements = "w15:*";
run.MCAttributes.ProcessContent = "";
result = validator.Validate(element);
Assert.False(result.Valid);
Assert.Equal(1, result.Errors.Count);
Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
Assert.Equal("MC_InvalidPreserveElementsAttribute", result.Errors[0].Id);
run.MCAttributes.Ignorable = "o15";
run.MCAttributes.PreserveAttributes = "";
run.MCAttributes.PreserveElements = "w15:*";
result = validator.Validate(element);
Assert.False(result.Valid);
Assert.Equal(1, result.Errors.Count);
Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
Assert.Equal("MC_InvalidPreserveElementsAttribute", result.Errors[0].Id);
run.MCAttributes.PreserveElements = null;
run.MCAttributes.ProcessContent = "w14:newW";
result = validator.Validate(element);
Assert.False(result.Valid);
Assert.Equal(1, result.Errors.Count);
Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
Assert.Equal("MC_InvalidProcessContentAttribute", result.Errors[0].Id);
run.MCAttributes.ProcessContent = null;
var spaceAttribute = new OpenXmlAttribute("xml:space", "http://www.w3.org/XML/1998/namespace", "preserve");
run.MCAttributes.ProcessContent = "o15:newP";
run.SetAttribute(spaceAttribute);
result = validator.Validate(element);
Assert.False(result.Valid);
Assert.Equal(1, result.Errors.Count);
Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
Assert.Equal("MC_InvalidXmlAttributeWithProcessContent", result.Errors[0].Id);
run.MCAttributes.ProcessContent = null;
run.SetAttribute(new OpenXmlAttribute("o15:id", "http://o15.com", "1"));
result = validator.Validate(element);
Assert.True(result.Valid);
run.MCAttributes.Ignorable = "o15 w15 x15";
result = validator.Validate(element);
Assert.False(result.Valid);
Assert.Equal(1, result.Errors.Count);
Assert.Equal(ValidationErrorType.MarkupCompatibility, result.Errors[0].ErrorType);
Assert.Equal("MC_InvalidIgnorableAttribute", result.Errors[0].Id);
run.MCAttributes.Ignorable = "o15 w15";
run.SetAttribute(new OpenXmlAttribute("x15:id", "http://x15.com", "1"));
result = validator.Validate(element);
Assert.False(result.Valid);
Assert.Equal(1, result.Errors.Count);
}