Class DocumentVisitor
名称: Aspose.Note 集合: Aspose.Note.dll (25.4.0)
抽象的类,以便通过指定的节点上根的地下树进行异化。
public abstract class DocumentVisitor
Inheritance
继承人
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Examples
显示如何使用访问者访问文档的内容。
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
// Open the document we want to convert.
Document doc = new Document(dataDir + "Aspose.one");
// Create an object that inherits from the DocumentVisitor class.
MyOneNoteToTxtWriter myConverter = new MyOneNoteToTxtWriter();
// This is the well known Visitor pattern. Get the model to accept a visitor.
// The model will iterate through itself by calling the corresponding methods
// on the visitor object (this is called visiting).
//
// Note that every node in the object model has the Accept method so the visiting
// can be executed not only for the whole document, but for any node in the document.
doc.Accept(myConverter);
// Once the visiting is complete, we can retrieve the result of the operation,
// that in this example, has accumulated in the visitor.
Console.WriteLine(myConverter.GetText());
Console.WriteLine(myConverter.NodeCount);
}
/// <summary>
/// Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
/// </summary>
public class MyOneNoteToTxtWriter : DocumentVisitor
{
public MyOneNoteToTxtWriter()
{
nodecount = 0;
mIsSkipText = false;
mBuilder = new StringBuilder();
}
/// <summary>
/// Gets the plain text of the document that was accumulated by the visitor.
/// </summary>
public string GetText()
{
return mBuilder.ToString();
}
/// <summary>
/// Adds text to the current output. Honors the enabled/disabled output flag.
/// </summary>
private void AppendText(string text)
{
if (!mIsSkipText)
{
mBuilder.AppendLine(text);
}
}
/// <summary>
/// Called when a RichText node is encountered in the document.
/// </summary>
public override void VisitRichTextStart(RichText run)
{
++nodecount;
AppendText(run.Text);
}
/// <summary>
/// Called when a Document node is encountered in the document.
/// </summary>
public override void VisitDocumentStart(Document document)
{
++nodecount;
}
/// <summary>
/// Called when a Page node is encountered in the document.
/// </summary>
public override void VisitPageStart(Page page)
{
++nodecount;
this.AppendText($"*** Page '{page.Title?.TitleText?.Text ?? "(no title)"}' ***");
}
/// <summary>
/// Called when processing of a Page node is finished.
/// </summary>
public override void VisitPageEnd(Page page)
{
this.AppendText(string.Empty);
}
/// <summary>
/// Called when a Title node is encountered in the document.
/// </summary>
public override void VisitTitleStart(Title title)
{
++nodecount;
}
/// <summary>
/// Called when a Image node is encountered in the document.
/// </summary>
public override void VisitImageStart(Image image)
{
++nodecount;
}
/// <summary>
/// Called when a OutlineGroup node is encountered in the document.
/// </summary>
public override void VisitOutlineGroupStart(OutlineGroup outlineGroup)
{
++nodecount;
}
/// <summary>
/// Called when a Outline node is encountered in the document.
/// </summary>
public override void VisitOutlineStart(Outline outline)
{
++nodecount;
}
/// <summary>
/// Called when a OutlineElement node is encountered in the document.
/// </summary>
public override void VisitOutlineElementStart(OutlineElement outlineElement)
{
++nodecount;
}
/// <summary>
/// Gets the total count of nodes by the Visitor
/// </summary>
public Int32 NodeCount
{
get { return this.nodecount; }
}
private readonly StringBuilder mBuilder;
private bool mIsSkipText;
private Int32 nodecount;
}
Constructors
DocumentVisitor()
protected DocumentVisitor()
Methods
VisitAttachedFileEnd(AttachedFile)
请访问 Aspose.Note.AttachedFile 节点。
public virtual void VisitAttachedFileEnd(AttachedFile attachedFile)
Parameters
attachedFile
AttachedFile
此分類上一篇: Aspose.Note.AttachedFile node
VisitAttachedFileStart(AttachedFile)
开始访问 Aspose.Note.AttachedFile 节点。
public virtual void VisitAttachedFileStart(AttachedFile attachedFile)
Parameters
attachedFile
AttachedFile
此分類上一篇: Aspose.Note.AttachedFile node
VisitDocumentEnd(Document)
请访问 Aspose.Note.Document 节点。
public virtual void VisitDocumentEnd(Document document)
Parameters
document
Document
Aspose.Note.文件节点。
VisitDocumentStart(Document)
开始访问 Aspose.Note.文件节点。
public virtual void VisitDocumentStart(Document document)
Parameters
document
Document
Aspose.Note.文件节点。
VisitImageEnd(Image)
请访问 Aspose.Note.图像节点。
public virtual void VisitImageEnd(Image image)
Parameters
image
Image
Aspose.Note.图像节点。
VisitImageStart(Image)
开始参观 Aspose.Note.图像节点。
public virtual void VisitImageStart(Image image)
Parameters
image
Image
Aspose.Note.图像节点。
VisitInkDrawingEnd(InkDrawing)
请访问 Aspose.Note.InkDrawing 节点。
public virtual void VisitInkDrawingEnd(InkDrawing inkDrawing)
Parameters
inkDrawing
InkDrawing
Aspose.Note.InkDrawing 节点。
VisitInkDrawingStart(InkDrawing)
开始参观 Aspose.Note.InkDrawing 节点。
public virtual void VisitInkDrawingStart(InkDrawing inkDrawing)
Parameters
inkDrawing
InkDrawing
Aspose.Note.InkDrawing 节点。
VisitInkParagraphEnd(InkParagraph)
请访问 Aspose.Note.InkParagraph 节点。
public virtual void VisitInkParagraphEnd(InkParagraph inkParagraph)
Parameters
inkParagraph
InkParagraph
Aspose.Note.InkParagraph 节点。
VisitInkParagraphStart(InkParagraph)
开始参观 Aspose.Note.InkParagraph 节点。
public virtual void VisitInkParagraphStart(InkParagraph inkParagraph)
Parameters
inkParagraph
InkParagraph
Aspose.Note.InkParagraph 节点。
VisitInkWordEnd(InkWord)
请访问 Aspose.Note.InkWord 节点。
public virtual void VisitInkWordEnd(InkWord inkWord)
Parameters
inkWord
InkWord
Aspose.Note.InkWord 节点。
VisitInkWordStart(InkWord)
开始访问 Aspose.Note.InkWord 节点。
public virtual void VisitInkWordStart(InkWord inkWord)
Parameters
inkWord
InkWord
Aspose.Note.InkWord 节点。
VisitLoopEnd(Loop)
请访问 Aspose.Note.Loop 节点。
public virtual void VisitLoopEnd(Loop loop)
Parameters
loop
Loop
此分類上一篇: WL31_.Loop node
VisitLoopStart(Loop)
开始参观 Aspose.Note.Loop 节点。
public virtual void VisitLoopStart(Loop loop)
Parameters
loop
Loop
此分類上一篇: WL31_.Loop node
VisitOutlineElementEnd(OutlineElement)
请访问 Aspose.Note.OutlineElement 节点。
public virtual void VisitOutlineElementEnd(OutlineElement outlineElement)
Parameters
outlineElement
OutlineElement
Aspose.Note.OutlineElement 节点。
VisitOutlineElementStart(OutlineElement)
开始参观 Aspose.Note.OutlineElement 节点。
public virtual void VisitOutlineElementStart(OutlineElement outlineElement)
Parameters
outlineElement
OutlineElement
Aspose.Note.OutlineElement 节点。
VisitOutlineEnd(Outline)
请访问 Aspose.Note.Outline 节点。
public virtual void VisitOutlineEnd(Outline outline)
Parameters
outline
Outline
此分類上一篇: Aspose.Note.Outline Node
VisitOutlineGroupEnd(OutlineGroup)
请访问 Aspose.Note.OutlineGroup 节点。
public virtual void VisitOutlineGroupEnd(OutlineGroup outlineGroup)
Parameters
outlineGroup
OutlineGroup
是 Aspose.Note.OutlineGroup 节点。
VisitOutlineGroupStart(OutlineGroup)
开始访问 Aspose.Note.OutlineGroup 节点。
public virtual void VisitOutlineGroupStart(OutlineGroup outlineGroup)
Parameters
outlineGroup
OutlineGroup
是 Aspose.Note.OutlineGroup 节点。
VisitOutlineStart(Outline)
开始参观 Aspose.Note.Outline 节点。
public virtual void VisitOutlineStart(Outline outline)
Parameters
outline
Outline
此分類上一篇: Aspose.Note.Outline Node
VisitPageEnd(Page)
请访问 Aspose.Note.Page 节点。
public virtual void VisitPageEnd(Page page)
Parameters
page
Page
是 Aspose.Note. 页面节点。
VisitPageStart(Page)
开始参观 Aspose.Note.页面节点。
public virtual void VisitPageStart(Page page)
Parameters
page
Page
是 Aspose.Note. 页面节点。
VisitRichTextEnd(RichText)
请访问 Aspose.Note.RichText 节点。
public virtual void VisitRichTextEnd(RichText richText)
Parameters
richText
RichText
Aspose.Note.RichText 节点。
VisitRichTextStart(RichText)
开始访问 Aspose.Note.RichText 节点。
public virtual void VisitRichTextStart(RichText richText)
Parameters
richText
RichText
Aspose.Note.RichText 节点。
VisitTableCellEnd(TableCell)
请访问 Aspose.Note.TableCell 节点。
public virtual void VisitTableCellEnd(TableCell tableCell)
Parameters
tableCell
TableCell
WL31_.TableCell 节点。
VisitTableCellStart(TableCell)
开始访问 Aspose.Note.TableCell 节点。
public virtual void VisitTableCellStart(TableCell tableCell)
Parameters
tableCell
TableCell
WL31_.TableCell 节点。
VisitTableEnd(Table)
请访问 Aspose.Note.Table 节点。
public virtual void VisitTableEnd(Table table)
Parameters
table
Table
此分類上一篇: WL31_.Table Node
VisitTableRowEnd(TableRow)
请访问 Aspose.Note.TableRow 节点。
public virtual void VisitTableRowEnd(TableRow tableRow)
Parameters
tableRow
TableRow
Aspose.Note.TableRow 节点。
VisitTableRowStart(TableRow)
开始参观 Aspose.Note.TableRow 节点。
public virtual void VisitTableRowStart(TableRow tableRow)
Parameters
tableRow
TableRow
Aspose.Note.TableRow 节点。
VisitTableStart(Table)
开始参观 Aspose.Note.表节点。
public virtual void VisitTableStart(Table table)
Parameters
table
Table
此分類上一篇: WL31_.Table Node
VisitTitleEnd(Title)
请访问 Aspose.Note.Title 节点。
public virtual void VisitTitleEnd(Title title)
Parameters
title
Title
WL31_.标题节点。
VisitTitleStart(Title)
开始参观 Aspose.Note.标题节点。
public virtual void VisitTitleStart(Title title)
Parameters
title
Title
WL31_.标题节点。