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


C# Body.RemoveChild方法代码示例

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


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

示例1: DomReaderMiscNodeTest

        public void DomReaderMiscNodeTest()
        {
            Body body = new Body(new Paragraph(new ParagraphProperties(), new Run(new Text("test"))));
            body.PrependChild( new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, "<!-- start body -->"));

            //======== new test with a new reader ========
            OpenXmlReader reader = OpenXmlReader.Create(body, true); // read misc nodes 
            Assert.False(reader.EOF);

            bool moved = reader.Read();
            Assert.True(moved);
            Assert.False(reader.EOF);
            Assert.Equal(0, reader.Depth);
            Assert.True(reader.IsStartElement);
            Assert.False(reader.IsEndElement);
            Assert.False(reader.IsMiscNode);
            Assert.Equal("body", reader.LocalName);

            moved = reader.Read();
            Assert.True(moved);
            Assert.False(reader.EOF);
            Assert.Equal(1, reader.Depth);
            Assert.False(reader.IsStartElement);
            Assert.False(reader.IsEndElement);
            Assert.True(reader.IsMiscNode);
            Assert.Equal("#comment", reader.LocalName);

            Assert.Equal(string.Empty, reader.Prefix);
            Assert.Equal(string.Empty, reader.NamespaceUri);

            reader.Close();

            // test case: for ReadFirstChild
            reader = OpenXmlReader.Create(body, true); // read misc nodes 
            Assert.False(reader.EOF);

            moved = reader.Read();
            Assert.False(reader.EOF);

            moved = reader.ReadFirstChild();
            Assert.True(moved);
            Assert.False(reader.EOF);
            Assert.Equal(1, reader.Depth);
            Assert.False(reader.IsStartElement);
            Assert.False(reader.IsEndElement);
            Assert.True(reader.IsMiscNode);
            Assert.Equal("#comment", reader.LocalName);

            Assert.Equal(string.Empty, reader.Prefix);
            Assert.Equal(string.Empty, reader.NamespaceUri);

            reader.Close();

            OpenXmlElement miscNode = body.RemoveChild(body.FirstChild);
            body.AppendChild(miscNode);

            reader = OpenXmlReader.Create(body, true); // read misc nodes 
            Assert.False(reader.EOF);

            moved = reader.Read();
            Assert.False(reader.EOF);

            moved = reader.ReadFirstChild();
            reader.Skip();

            Assert.True(moved);
            Assert.False(reader.EOF);
            Assert.Equal(1, reader.Depth);
            Assert.False(reader.IsStartElement);
            Assert.False(reader.IsEndElement);
            Assert.True(reader.IsMiscNode);

            Assert.Equal(string.Empty, reader.Prefix);
            Assert.Equal(string.Empty, reader.NamespaceUri);

            reader.Close();

            // test case: root element is misc node
            reader = OpenXmlReader.Create(new OpenXmlMiscNode(System.Xml.XmlNodeType.ProcessingInstruction, "<?pi test?>"), true);
            moved = reader.Read();
            Assert.True(moved);
            Assert.False(reader.EOF);
            Assert.Equal(0, reader.Depth);
            Assert.False(reader.IsStartElement);
            Assert.False(reader.IsEndElement);
            Assert.True(reader.IsMiscNode);
            Assert.Equal("pi", reader.LocalName);

            Assert.Equal(string.Empty, reader.Prefix);
            Assert.Equal(string.Empty, reader.NamespaceUri);

            reader.Close();

            // case bug #253890
            body = new Body(new Paragraph(new ParagraphProperties(), new Run(new Text("test"))));
            miscNode = body.AppendChild(new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, "<!-- start body -->"));

            reader = OpenXmlReader.Create(body.FirstChild, true);
            moved = reader.Read();
            Assert.True(moved);
//.........这里部分代码省略.........
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:101,代码来源:OpenXmlReaderTest.cs

示例2: ValidateBody


//.........这里部分代码省略.........
            Assert.True(actual.Valid);

            body.InsertAfter(new Paragraph(), body.FirstChild);
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.PrependChild(new MoveFromRangeStart());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.PrependChild(new MoveFromRun());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            //body.PrependChild(new DocumentFormat.OpenXml.Math.OfficeMath());
            //target.Validate(validationContext);
            //Assert.True(actual.Valid);

            //body.PrependChild(new DocumentFormat.OpenXml.Math.OfficeMath());
            //target.Validate(validationContext);
            //Assert.True(actual.Valid);

            body.PrependChild(new MoveFromRun());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.PrependChild(new MoveFromRangeStart());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.InsertAfter(new Paragraph(), body.FirstChild);
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******
            // sectProperties can not be the first
            errorChild = body.FirstChild;
            body.PrependChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            body.RemoveChild(body.FirstChild);

            actual.Clear();
            // can only have one sectProperties at last
            errorChild = body.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            body.RemoveChild(errorChild);

            actual.Clear();
            // paragrap can be after sectProperties at last
            errorChild = body.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            body.RemoveChild(errorChild);

            actual.Clear();
            // first is invalid
            errorChild = body.PrependChild(new Run());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":altChunk"));
            body.RemoveChild(errorChild);

            actual.Clear();
            // invalid child in middle
            errorChild = body.InsertBefore(new Run(), body.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            body.RemoveChild(errorChild);
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:101,代码来源:CompositeParticleValidatorTest.cs


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