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


C# Paragraph.AddNamespaceDeclaration方法代码示例

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


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

示例1: Bug704004

        private void Bug704004(OpenXmlValidator validator)
        {
            //<w:p>
            //    <ve:AlternateContent />
            //    <w:r>
            //        <w:t>Acb</w:t>
            //        <w:rPr>
            //            <w:rFonts w:hint="eastAsia"/>
            //        </w:rPr>
            //    </w:r>
            //</w:p>
            Paragraph p = new Paragraph();
            AlternateContent acb = p.AppendChild(new AlternateContent());
            // one error, w:rPr should before the w:t
            p.AppendChild(new Run(new DocumentFormat.OpenXml.Wordprocessing.Text() { Text = "Acb" },
                                  new RunProperties(new RunFonts() { Hint = FontTypeHintValues.EastAsia })
                                  )
                          );

            // an empty "AlternateContent"
            var errors = validator.Validate(p); // should no hang, no OOM
            Assert.Equal(2, errors.Count());
            Assert.Equal("Sch_IncompleteContentExpectingComplex", errors.First().Id);
            Assert.Same(p.FirstChild, errors.First().Node);  // acb should have a choice
            Assert.Same(p.FirstChild.NextSibling().FirstChild.NextSibling(), errors.ElementAt(1).RelatedNode);

            // append an empty "Choice"
            p.AddNamespaceDeclaration("w14", "http://w14");
            acb.AppendChild(new AlternateContentChoice() { Requires = "w14" });
            errors = validator.Validate(p); // should no hang, no OOM
            Assert.Equal(1, errors.Count());
            Assert.Same(p.FirstChild.NextSibling().FirstChild.NextSibling(), errors.ElementAt(0).RelatedNode);

            // append an empty "Fallback"
            acb.AppendChild(new AlternateContentFallback() );
            errors = validator.Validate(p); // should no hang, no OOM
            Assert.Equal(1, errors.Count());
            Assert.Same(p.FirstChild.NextSibling().FirstChild.NextSibling(), errors.ElementAt(0).RelatedNode);
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:39,代码来源:BugRegressionTest.cs

示例2: AcbValidationTest

        public void AcbValidationTest()
        {
            MCContext mcContext = new MCContext();
            ParagraphProperties pPr;
            Run run1, run2;
            Paragraph p = new Paragraph(pPr = new ParagraphProperties() { WordWrap = new WordWrap() { Val = true } },
                                         new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, "<!-- comments -->"),
                                         run1 = new Run(new Text("Text 1.")),
                                         run2 = new Run(new Text("Text 2.")));

            p.AddNamespaceDeclaration("w14test", "http://w14.com");

            OpenXmlUnknownElement ignorableElement = new OpenXmlUnknownElement("w14test", "span", "http://w14.com");
            ignorableElement.MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14test" };
            p.InsertAfter(ignorableElement, pPr);

            Run runInAcb = new Run(new Text("Text in ACB."));
            Run run2InAcb = new Run(new Text("Text 2 in ACB."));
            AlternateContent acb = new AlternateContent(new AlternateContentChoice() { Requires = "w14test" },
                                                        new AlternateContentFallback(runInAcb, run2InAcb));
            p.InsertAfter(acb, pPr);

            var validator = new OpenXmlValidator();
            var errors = validator.Validate(p);
            Assert.Equal(0, errors.Count());

            p.AppendChild(new OpenXmlUnknownElement("w15test", "art", "http://w15.com"));
            errors = validator.Validate(p);
            Assert.Equal(1, errors.Count());
            p.RemoveChild(p.LastChild);

            acb.LastChild.Append(new OpenXmlUnknownElement("w15test", "art", "http://w15.com"));
            errors = validator.Validate(p);
            Assert.Equal(1, errors.Count());

        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:36,代码来源:McValidationTest.cs

示例3: 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);
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:96,代码来源:McValidationTest.cs

示例4: GetChildMcTest

        public void GetChildMcTest()
        {
            MCContext mcContext = new MCContext();
            ParagraphProperties pPr;
            Run run1, run2;
            Paragraph p = new Paragraph(pPr = new ParagraphProperties() { WordWrap = new WordWrap() { Val = true } },
                                         new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, "<!-- comments -->"),
                                         run1 = new Run(new Text("Text 1.")),
                                         run2 = new Run(new Text("Text 2.")));

            var target = p.GetFirstChildMc(mcContext, FileFormatVersions.Office2007);
            Assert.Same(pPr, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run1, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run2, target);

            OpenXmlUnknownElement ignorableElement = new OpenXmlUnknownElement("w14test", "span", "http://w14.com");
            p.AddNamespaceDeclaration("w14test", "http://w14.com");

            ignorableElement.MCAttributes = new MarkupCompatibilityAttributes() { Ignorable="w14test" };
            p.InsertAfter(ignorableElement, pPr);
            
            mcContext = new MCContext();
            target = p.GetFirstChildMc(mcContext, FileFormatVersions.Office2007);
            Assert.Same(pPr, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run1, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run2, target);

            Run runInAcb = new Run(new Text("Text in ACB."));
            AlternateContent acb = new AlternateContent(new AlternateContentChoice() { Requires = "w14test" },
                                                        new AlternateContentFallback(runInAcb));
            p.InsertAfter(acb, pPr);

            mcContext = new MCContext();
            target = p.GetFirstChildMc(mcContext, FileFormatVersions.Office2007);
            Assert.Same(pPr, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(runInAcb, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run1, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run2, target);



        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:49,代码来源:McValidationTest.cs

示例5: NSDeclTest

        public void NSDeclTest()
        {
            var p = new Paragraph();
            p.ParagraphId = "123";
            //NamespaceDeclarations is not null
            Assert.Equal(0, p.NamespaceDeclarations.Count());

            p.AddNamespaceDeclaration("a", "http://b");
            p.SetAttribute(new OpenXmlAttribute("t", "tt", "http://t", "abcd"));

            Assert.Equal(null, p.LookupPrefix("http://t"));
            Assert.Equal(null, p.LookupPrefix("http://schemas.microsoft.com/office/word/2010/wordml\""));

            var xmlcontent = "<w:p xmlns:a=\"http://b\" w14:paraId=\"123\" t:tt=\"abcd\" xmlns:t=\"http://t\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" />";
            Assert.Equal(xmlcontent, p.OuterXml);
            Assert.Equal(1, p.ExtendedAttributes.Count());
            Assert.Equal(1, p.NamespaceDeclarations.Count());

            p = new Paragraph(xmlcontent);
            Assert.Equal(1, p.ExtendedAttributes.Count());
            Assert.Equal(4, p.NamespaceDeclarations.Count());

            Assert.Equal("a", p.LookupPrefix("http://b"));

            Assert.Equal("t", p.LookupPrefix("http://t"));
            Assert.Equal("w14", p.LookupPrefix("http://schemas.microsoft.com/office/word/2010/wordml"));

            p.RemoveNamespaceDeclaration("t");
            Assert.Equal(null, p.LookupPrefix("http://t"));
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:30,代码来源:OpenXmlElementTest.cs


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