RemoveSelfOnly
Contents
[
Hide
]StructuredDocumentTagRangeStart.RemoveSelfOnly method
Removes this range start and appropriate range end nodes of the structured document tag, but keeps its content inside the document tree.
public void RemoveSelfOnly()
Examples
Shows how to create/remove structured document tag and its content.
public void SdtRangeExtendedMethods()
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("StructuredDocumentTag element");
StructuredDocumentTagRangeStart rangeStart = InsertStructuredDocumentTagRanges(doc);
// Removes ranged structured document tag, but keeps content inside.
rangeStart.RemoveSelfOnly();
rangeStart = (StructuredDocumentTagRangeStart)doc.GetChild(
NodeType.StructuredDocumentTagRangeStart, 0, false);
Assert.AreEqual(null, rangeStart);
StructuredDocumentTagRangeEnd rangeEnd = (StructuredDocumentTagRangeEnd)doc.GetChild(
NodeType.StructuredDocumentTagRangeEnd, 0, false);
Assert.AreEqual(null, rangeEnd);
Assert.AreEqual("StructuredDocumentTag element", doc.GetText().Trim());
rangeStart = InsertStructuredDocumentTagRanges(doc);
Node paragraphNode = rangeStart.LastOrDefault();
Assert.AreEqual("StructuredDocumentTag element", paragraphNode?.GetText().Trim());
// Removes ranged structured document tag and content inside.
rangeStart.RemoveAllChildren();
paragraphNode = rangeStart.LastOrDefault();
Assert.AreEqual(null, paragraphNode?.GetText());
}
public StructuredDocumentTagRangeStart InsertStructuredDocumentTagRanges(Document doc)
{
StructuredDocumentTagRangeStart rangeStart = new StructuredDocumentTagRangeStart(doc, SdtType.PlainText);
StructuredDocumentTagRangeEnd rangeEnd = new StructuredDocumentTagRangeEnd(doc, rangeStart.Id);
doc.FirstSection.Body.InsertBefore(rangeStart, doc.FirstSection.Body.FirstParagraph);
doc.LastSection.Body.InsertAfter(rangeEnd, doc.FirstSection.Body.FirstParagraph);
return rangeStart;
}
See Also
- class StructuredDocumentTagRangeStart
- namespace Aspose.Words.Markup
- assembly Aspose.Words