ASPOSE home

com.aspose.words
Class Document

java.lang.Object
  extended by Node
      extended by CompositeNode
          extended by com.aspose.words.Document
All Implemented Interfaces:
java.lang.Iterable, java.lang.Cloneable

public class Document
extends CompositeNode

Represents a Word document.

The Document is a central object in the Aspose.Words library.

Microsoft Word 97 and higher binary DOC formats are supported. Aspose.Words for Java does not support HTML, PDF or RTF at the moment.

To open an existing DOC document, pass a file name or a stream into one of the Document constructors. To create a blank document, call the constructor without parameters.

Use one of the Save method overloads to save the document in DOC format.

MailMerge is the Aspose.Words's reporting engine that allows to populate reports designed in Microsoft Word with data from various data sources quickly and easily. The data can be from a java.sql.ResultSet or an array of values. MailMerge will go through the records found in the data source and insert them into mail merge fields in the document growing it as necessary.

Document stores document-wide information such as Styles, BuiltInDocumentProperties, CustomDocumentProperties, lists and macros. Most of these objects are accessible via the corresponding properties of the Document.

The Document is a root node of a tree that contains all other nodes of the document. The tree is a Composite design pattern and in many ways similar to XmlDocument. The content of the document can be manipulated freely programmatically:

Consider using DocumentBuilder that simplifies the task of programmatically creating or populating the document tree.

The Document can contain only Section objects.

In Microsoft Word, a valid document needs to have at least one section.


Constructor Summary
Document()
           Creates a blank Word document.
Document(java.lang.String fileName)
           Opens an existing document from a file.
Document(java.lang.String fileName, int loadFormat, java.lang.String password)
           Opens an existing document from a file.
Document(java.nio.ByteBuffer byteBuffer)
           Opens an existing document from a ByteBuffer.
Document(java.io.InputStream stream)
           Opens an existing document from a stream.
Document(java.nio.ByteBuffer byteBuffer, java.lang.String baseUri, int loadFormat, java.lang.String password)
           Opens an existing document from a ByteBuffer.
Document(java.io.InputStream stream, java.lang.String baseUri, int loadFormat, java.lang.String password)
           Opens an existing document from a stream.
 
Property Getters/Setters Summary
java.lang.StringgetAttachedTemplate()
voidsetAttachedTemplate(java.lang.String value)
           Gets or sets the full path of the template attached to the document.
BuiltInDocumentPropertiesgetBuiltInDocumentProperties()
           Returns a collection that represents all the built-in document properties of the document.
NodeCollectiongetChildNodes()→ inherited from CompositeNode
           Gets all immediate child nodes of this node.
CompatibilityOptionsgetCompatibilityOptions()
           Provides document compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Word).
intgetCount()→ inherited from CompositeNode
           Gets the number of immediate children of this node.
CustomDocumentPropertiesgetCustomDocumentProperties()
           Returns a collection that represents all the custom document properties of the document.
doublegetDefaultTabStop()
voidsetDefaultTabStop(double value)
           Gets or sets the interval (in points) between the default tab stops.
DocumentgetDocument()→ inherited from Node
           Gets the document to which this node belongs.
NodegetFirstChild()→ inherited from CompositeNode
           Gets the first child of the node.
SectiongetFirstSection()
           Gets the first section in the document.
booleanhasChildNodes()→ inherited from CompositeNode
           Returns true if this node has any child nodes.
booleanhasMacros()
           Returns true if the document has a VBA project.
booleanhasRevisions()
           Returns true if the document has any tracked changes.
booleanisComposite()→ inherited from CompositeNode
           Returns true as this node can have child nodes.
booleanisTemplate()
voidisTemplate(boolean value)
           Specifies whether the document is a template or a normal document.
NodegetLastChild()→ inherited from CompositeNode
           Gets the last child of the node.
SectiongetLastSection()
           Gets the last section in the document.
ListsgetLists()
           Provides access to the list formatting used in the document.
MailMergegetMailMerge()
           Returns a MailMerge object that represents the mail merge functionality for the document.
NodegetNextSibling()→ inherited from Node
           Gets the node immediately following this node.
intgetNodeType()
           Returns NodeType.Document. The value of the property is NodeType integer constant.
java.lang.StringgetOriginalFileName()
           Gets the original file name of the document.
CompositeNodegetParentNode()→ inherited from Node
           Gets the immediate parent of this node.
NodegetPreviousSibling()→ inherited from Node
           Gets the node immediately preceding this node.
intgetProtectionType()
voidsetProtectionType(int value)
           Gets or sets the document protection type. The value of the property is ProtectionType integer constant.
RangegetRange()→ inherited from Node
           Returns a Range object that represents the portion of a document that is contained in this node.
SectionsgetSections()
           Returns a Sections collection that represents the sections in the document.
booleangetShadeFormData()
voidsetShadeFormData(boolean value)
           Specifies whether to turn on the gray shading on form fields.
StylesgetStyles()
           Returns a collection of styles defined in the document.
VariablesgetVariables()
           Returns the collection of variables added to a document or template.
ViewOptionsgetViewOptions()
           Provides options to control how the document is displayed in Microsoft Word.
 
Method Summary
booleanaccept(DocumentVisitor visitor)
           Accepts a visitor.
voidacceptAllRevisions()
           Accepts all tracked changes in the document.
voidaddNodeChangedEventHandler(NodeChangedEventHandler newListener)
          Adds the NodeChangedEventHandler to the list of subscribed listeners of one of Node Changed event.
NodeappendChild(Node newChild)→ inherited from CompositeNode
           Adds the specified node to the end of the list of child nodes for this node.
DocumentdeepClone()
           Performs a deep copy of the Document.
NodedeepClone(boolean isCloneChildren)
           Creates a duplicate of the document.
voidensureMinimum()
           If the document contains no sections, creates one section with one paragraph.
NodegetAncestor(java.lang.Class ancestorType)→ inherited from Node
           Gets the first ancestor of the specified type.
NodegetChild(int nodeType, int index, boolean isDeep)→ inherited from CompositeNode
           Returns an Nth child node that matches the specified type.
NodeCollectiongetChildNodes(int nodeType, boolean isDeep)→ inherited from CompositeNode
           Returns a live collection of child nodes that match the specified type.
NodeCollectiongetChildNodes(int nodeType, boolean isDeep, boolean isLive)→ inherited from CompositeNode
           Returns a "live" or "snapshot" collection of child node that match the specified type.
java.lang.StringgetText()→ inherited from CompositeNode
           Gets the text of this node and of all its children.
NodeimportNode(Node srcNode, boolean isImportChildren)
          

Imports a node from another document to the current document.

NodeimportNode(Node srcNode, boolean isImportChildren, int importFormatMode)
          

Imports a node from another document to the current document with an option to control formatting.

intindexOf(Node child)→ inherited from CompositeNode
           Returns the index of the specified child node in the child node array.
NodeinsertAfter(Node newChild, Node refChild)→ inherited from CompositeNode
           Inserts the specified node immediately after the specified reference node.
NodeinsertBefore(Node newChild, Node refChild)→ inherited from CompositeNode
           Inserts the specified node immediately before the specified reference node.
java.util.Iteratoriterator()→ inherited from CompositeNode
           Provides support for the for each style iteration over the child nodes of this node.
NodenextPreOrder(Node rootNode)→ inherited from Node
           Gets next node according to the pre-order tree traversal algorithm.
NodeprependChild(Node newChild)→ inherited from CompositeNode
           Adds the specified node to the beginning of the list of child nodes for this node.
NodepreviousPreOrder(Node rootNode)→ inherited from Node
           Gets the previous node according to the pre-order tree traversal algorithm.
voidprotect(int type)
           Protects the document from changes.
voidremove()→ inherited from Node
           Removes itself from the parent.
voidremoveAllChildren()→ inherited from CompositeNode
           Removes all the child nodes of the current node.
NoderemoveChild(Node oldChild)→ inherited from CompositeNode
           Removes the specified child node.
voidremoveMacros()
           Removes all macros (the VBA project) from the document.
voidremoveNodeChangedEventHandler(NodeChangedEventHandler oldListener)
          Removes the NodeChangedEventHandler from the list of subscribed listeners of Node Changed event.
voidsave(java.io.OutputStream outputStream, int saveFormat)
           Saves the document to a stream.
voidsave(java.lang.String fileName)
           Saves the document to a file. Automatically determine the file format from the extension.
voidsave(java.lang.String fileName, int fileFormat)
           Saves the document with a new name or format.
NodeListselectNodes(java.lang.String xpath)→ inherited from CompositeNode
           Selects a list of nodes matching the XPath expression.
NodeselectSingleNode(java.lang.String xpath)→ inherited from CompositeNode
           Selects the first Node that matches the XPath expression.
java.lang.StringtoTxt()→ inherited from Node
           Exports the content of the node into a string in TXT (plain text) format.
voidunprotect()
           Removes protection from the document.
voidupdateTableLayout()
           Updates widths of cells and tables according to their preferred widths and content.
voidupdateWordCount()
           Updates word count properties of the document.
 

Constructor Detail

Document

public Document()
         throws java.lang.Exception
Creates a blank Word document.

The document paper size is Letter by default. If you want to change page setup, use Section.PageSetup.

After creation, you can use DocumentBuilder to add document content easily.


Document

public Document(java.lang.String fileName)
         throws java.lang.Exception
Opens an existing document from a file.
Parameters:
fileName - File name of the document to open.

Document

public Document(java.lang.String fileName, int loadFormat, java.lang.String password)
         throws java.lang.Exception
Opens an existing document from a file.

If you know the format of the document upfront, you can use this constructor and specify the format. It will work slightly faster than other constructors that detect the format of the file automatically. It is only LoadFormat.FORMAT_DOCUMENT and LoadFormat.FORMAT_AUTO supported in Java at the moment.

Use this constructor to open an encrypted Microsoft Word document. You need to know the password to open an encrypted document. If the document is not encrypted, pass null or empty string.

Parameters:
fileName - File name of the document to open.
loadFormat - A LoadFormat value. Specifies the format of the document.
password - A password to open an encrypted Word document. Pass null or empty string if the document is not encrypted.

Document

public Document(java.nio.ByteBuffer byteBuffer)
         throws java.lang.Exception
Opens an existing document from a ByteBuffer.

The document must be stored at the beginning of the ByteBuffer. Note: the ctor calls ByteBufer.rewind() to set zero position and ByteBufer.remaining() to get the length, so limit mast be set properly.


Document

public Document(java.io.InputStream stream)
         throws java.lang.Exception
Opens an existing document from a stream.

The document must be stored at the beginning of the stream. For reading java.nio Channels one can use java.nio.Channels.newInputStream(ReadableByteChannel) to convert Channel to InputStream

Parameters:
stream - Stream where to load the document from.

Document

public Document(java.nio.ByteBuffer byteBuffer, java.lang.String baseUri, int loadFormat, java.lang.String password)
         throws java.lang.Exception
Opens an existing document from a ByteBuffer.

The document must be stored at the beginning of the ByteBuffer. Note: the ctor calls ByteBufer.rewind() to set zero position and ByteBufer.remaining() to get the length, so limit mast be set properly.

If you know the format of the document upfront, you can use this constructor and specify the format. It will work slightly faster than other constructors that detect the format of the file automatically. It is only LoadFormat.FORMAT_DOCUMENT and LoadFormat.FORMAT_AUTO supported in Java at the moment.

Use this constructor to open an encrypted Microsoft Word document. You need to know the password to open an encrypted document. If the document is not encrypted, pass null or empty string.

The baseUri parameter is used with HTML and PDF document formats and not supported in Java at the moment.

Parameters:
byteBuffer - ByteBuffer where to load the document from.
baseUri - The base URI. Can be null or empty string. In Java ignored at the moment.
loadFormat - A LoadFormat value that specifies the format of the document.
password - A password to open an encrypted Word document. Pass null or empty string if the document is not encrypted.

Document

public Document(java.io.InputStream stream, java.lang.String baseUri, int loadFormat, java.lang.String password)
         throws java.lang.Exception
Opens an existing document from a stream.

The document must be stored at the beginning of the stream. For reading java.nio Channels one can use java.nio.Channels.newInputStream(ReadableByteChannel) to convert Channel to InputStream

If you know the format of the document upfront, you can use this constructor and specify the format. It will work slightly faster than other constructors that detect the format of the file automatically. It is only LoadFormat.FORMAT_DOCUMENT and LoadFormat.FORMAT_AUTO supported in Java at the moment.

Use this constructor to open an encrypted Microsoft Word document. You need to know the password to open an encrypted document. If the document is not encrypted, pass null or empty string.

The baseUri parameter is used with HTML and PDF document formats and not supported in Java at the moment.

Parameters:
stream - The stream where to load the document from.
baseUri - The base URI. Can be null or empty string. In Java ignored at the moment.
loadFormat - A LoadFormat value that specifies the format of the document.
password - A password to open an encrypted Word document. Pass null or empty string if the document is not encrypted.

Property Getters/Setters Detail

getAttachedTemplate/setAttachedTemplate

public java.lang.String getAttachedTemplate()

public void setAttachedTemplate(java.lang.String value)
Gets or sets the full path of the template attached to the document.

Empty string means the document is attached to the Normal template.

Throws if you attempt to set to a null value.
See Also:
BuiltInDocumentProperties.Template

isTemplate/isTemplate

public boolean isTemplate()

public void isTemplate(boolean value)
Specifies whether the document is a template or a normal document.

The type of the document (template or document) is controlled by this property and stored inside the document. The type of the document is not controlled by the file extension.

Aspose.Words sets this property to false when the document is loaded into memory. This means that when you save a document, it will be saved as a Microsoft Word Document by default. If you want to save your document as a Microsoft Word Document Template, you need to set this property to true before saving.

A likely scenario for Aspose.Words is to open a document (.DOC or .DOT), populate it with data and save as a .DOC document. If Aspose.Words did not reset this property to false automatically, you could end up saving Microsoft Word Document Templates.

When the document is a template, Microsoft Word 2003 suggests the Document Template file type with the .DOT extension in the Save As dialog box. Earlier versions of Microsoft Word disallow selecting the file type altogether.


getShadeFormData/setShadeFormData

public boolean getShadeFormData()

public void setShadeFormData(boolean value)
Specifies whether to turn on the gray shading on form fields.

getNodeType

public int getNodeType()
Returns NodeType.Document. The value of the property is NodeType integer constant.

getBuiltInDocumentProperties

public BuiltInDocumentProperties getBuiltInDocumentProperties()
Returns a collection that represents all the built-in document properties of the document.

getCustomDocumentProperties

public CustomDocumentProperties getCustomDocumentProperties()
Returns a collection that represents all the custom document properties of the document.

getVariables

public Variables getVariables()
Returns the collection of variables added to a document or template.

getStyles

public Styles getStyles()
Returns a collection of styles defined in the document.

getMailMerge

public MailMerge getMailMerge()
Returns a MailMerge object that represents the mail merge functionality for the document.

getProtectionType/setProtectionType

public int getProtectionType()

public void setProtectionType(int value)
Gets or sets the document protection type. The value of the property is ProtectionType integer constant.

ProtectionType allows to retrieve and change document protection type.

Protect and Unprotect methods allow to change protection type, but do not allow to retrieve it and are available to mimic Microsoft Word object model.

When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form.

When you protect a document, and the document does not have a protection password, Aspose.Words assigns a random password that makes it impossible to unprotect the document in MS Word, but you still can unprotect the document in Aspose.Words as it does not require a password when unprotecting.

When you protect a document, and the document already has a protection password, the existing protection password is not changed.


getSections

public Sections getSections()
Returns a Sections collection that represents the sections in the document.

getFirstSection

public Section getFirstSection()
Gets the first section in the document. Returns null if there are no sections.

getLastSection

public Section getLastSection()
Gets the last section in the document. Returns null if there are no sections.

getViewOptions

public ViewOptions getViewOptions()
Provides options to control how the document is displayed in Microsoft Word.

getCompatibilityOptions

public CompatibilityOptions getCompatibilityOptions()
Provides document compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Word).

hasRevisions

public boolean hasRevisions()
Returns true if the document has any tracked changes.
See Also:
acceptAllRevisions()

hasMacros

public boolean hasMacros()
Returns true if the document has a VBA project.
See Also:
removeMacros()

getDefaultTabStop/setDefaultTabStop

public double getDefaultTabStop()

public void setDefaultTabStop(double value)
Gets or sets the interval (in points) between the default tab stops.
See Also:
TabStops, TabStop

getLists

public Lists getLists()
Provides access to the list formatting used in the document.

For more information see the description of the Lists class.

See Also:
Lists, List, ListFormat

getOriginalFileName

public java.lang.String getOriginalFileName()
Gets the original file name of the document.

Returns null if the document was loaded from a stream or created blank.


isComposite

→ inherited from CompositeNode
public boolean isComposite()
Returns true as this node can have child nodes.

hasChildNodes

→ inherited from CompositeNode
public boolean hasChildNodes()
Returns true if this node has any child nodes.

getChildNodes

→ inherited from CompositeNode
public NodeCollection getChildNodes()
Gets all immediate child nodes of this node.

If there are no child nodes, this property returns an empty collection.

ChildNodes is equivalent to calling GetChildNodes(NodeType.Any, false).


getFirstChild

→ inherited from CompositeNode
public Node getFirstChild()
Gets the first child of the node. If there is no first child node, a null is returned.

getLastChild

→ inherited from CompositeNode
public Node getLastChild()
Gets the last child of the node. If there is no last child node, a null is returned.

getCount

→ inherited from CompositeNode
public int getCount()
Gets the number of immediate children of this node.

getParentNode

→ inherited from Node
public CompositeNode getParentNode()
Gets the immediate parent of this node.

If a node has just been created and not yet added to the tree, or if it has been removed from the tree, the parent is null.


getDocument

→ inherited from Node
public Document getDocument()
Gets the document to which this node belongs.

The node always belongs to a document even if it has just been created and not yed added to the tree, or if it has been removed from the tree.


getPreviousSibling

→ inherited from Node
public Node getPreviousSibling()
Gets the node immediately preceding this node.

If there is no preceding node, a null is returned.

Note: Calculating the value of this property iterates from the first child node of ParenNode to this node.

getNextSibling

→ inherited from Node
public Node getNextSibling()
Gets the node immediately following this node. If there is no next node, a null is returned.

getRange

→ inherited from Node
public Range getRange()
Returns a Range object that represents the portion of a document that is contained in this node.

Method Detail

iterator

→ inherited from CompositeNode
public java.util.Iterator iterator()
Provides support for the for each style iteration over the child nodes of this node.

getText

→ inherited from CompositeNode
public java.lang.String getText()
Gets the text of this node and of all its children.

The returned string includes all control and special characters as described in ControlChar.


accept

public boolean accept(DocumentVisitor visitor)
              throws java.lang.Exception
Accepts a visitor.

Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.

For more info see the Visitor design pattern.

Calls DocumentVisitor.VisitDocumentStart, then calls Accept for all child nodes of the document and calls DocumentVisitor.VisitDocumentEnd at the end.
Parameters:
visitor - The visitor that will visit the nodes.
Returns:
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.

deepClone

public Node deepClone(boolean isCloneChildren)
              throws java.lang.Exception
Creates a duplicate of the document.

If you need to generate many documents from a single document, just load the document into memory once, clone it and populate the cloned document with your data. This speeds up generation of documents because there is no need to load and parse the document from file every time.

Parameters:
isCloneChildren - True to recursively clone the content of the document; false to clone only the document node and document-wide objects styles, lists, document properties etc.
Returns:
The cloned document.

deepClone

public Document deepClone()
                  throws java.lang.Exception
Performs a deep copy of the Document.
Returns:
The cloned document.

save

public void save(java.lang.String fileName)
         throws java.lang.Exception
Saves the document to a file. Automatically determine the file format from the extension.
Parameters:
fileName - The name for the document. If a document with the specified file name already exists, the existing document is overwritten.
See Also:
IsTemplate

save

public void save(java.lang.String fileName, int fileFormat)
         throws java.lang.Exception
Saves the document with a new name or format.
Parameters:
fileName - The name for the document. If a document with the specified file name already exists, the existing document is overwritten.
fileFormat - A SaveFormat value that specifies the format in which the document is saved. Only SaveFormat.DOC and SaveFormat.TEXT supported in Java at the moment.
See Also:
IsTemplate

save

public void save(java.io.OutputStream outputStream, int saveFormat)
         throws java.lang.Exception
Saves the document to a stream.
Parameters:
stream - Stream where to save the document.
saveFormat - A SaveFormat value that specifies the format in which the document is saved. Only SaveFormat.DOC and SaveFormat.TEXT supported in Java at the moment.
See Also:
IsTemplate

importNode

public Node importNode(Node srcNode, boolean isImportChildren)
               throws java.lang.Exception

Imports a node from another document to the current document.

This method uses the ImportFormatMode.USE_DESTINATION_STYLES option to resolve formatting.

Importing a node creates a copy of the source node belonging to the importing document. The returned node has no parent. The source node is not altered or removed from the original document.

Before a node from another document can be inserted into this document, it must be imported. During import, document-specific properties such as references to styles and lists are translated from the original to the importing document. After the node was imported, it can be inserted into the appropriate place in the document using insertBefore(com.aspose.words.Node, com.aspose.words.Node) or insertAfter(com.aspose.words.Node, com.aspose.words.Node).

If the source node already belongs to the destination document, then simply a deep clone of the source node is created.

Parameters:
srcNode - The node being imported.
isImportChildren - True to import all child nodes recursively; otherwise, false.
Returns:
The cloned node that belongs to the current document.
See Also:
NodeImporter

importNode

public Node importNode(Node srcNode, boolean isImportChildren, int importFormatMode)
               throws java.lang.Exception

Imports a node from another document to the current document with an option to control formatting.

This overload is useful to control how styles and list formatting are imported.

Importing a node creates a copy of the source node belonging to the importing document. The returned node has no parent. The source node is not altered or removed from the original document.

Before a node from another document can be inserted into this document, it must be imported. During import, document-specific properties such as references to styles and lists are translated from the original to the importing document. After the node was imported, it can be inserted into the appropriate place in the document using insertBefore(com.aspose.words.Node, com.aspose.words.Node) or insertAfter(com.aspose.words.Node, com.aspose.words.Node).

If the source node already belongs to the destination document, then simply a deep clone of the source node is created.

Parameters:
srcNode - The node to imported.
isImportChildren - True to import all child nodes recursively; otherwise, false.
importFormatMode - A ImportFormatMode value. Specifies how to merge style formatting that clashes.
Returns:
The cloned, imported node. The node belongs to the destination document, but has no parent.
See Also:
ImportFormatMode, NodeImporter

ensureMinimum

public void ensureMinimum()
                  throws java.lang.Exception
If the document contains no sections, creates one section with one paragraph.

acceptAllRevisions

public void acceptAllRevisions()
                       throws java.lang.Exception
Accepts all tracked changes in the document.

protect

public void protect(int type)
Protects the document from changes.

When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form.

When you protect a document, and the document does not have a protection password, Aspose.Words assigns a random password that makes it impossible to unprotect the document in MS Word, but you still can unprotect the document in Aspose.Words as it does not require a password when unprotecting.

When you protect a document, and the document already has a protection password, the existing protection password is not changed.

Parameters:
type - A ProtectionType value. Specifies the protection type for the document.

unprotect

public void unprotect()
Removes protection from the document. This method unprotects the document even if it has a protection password.

updateWordCount

public void updateWordCount()
                    throws java.lang.Exception
Updates word count properties of the document.

UpdateWordCount recalculates and updates Characters, Words and Paragraphs properties in the BuiltInDocumentProperties collection of the Document.

Note that UpdateWordCount does not update number of lines and pages properties.

When you use an evaluation version, the evaluation watermark will also be included in the word count.


updateTableLayout

public void updateTableLayout()
                      throws java.lang.Exception
Updates widths of cells and tables according to their preferred widths and content.

You don't normally need to call this method as cell and table widths are maintained automatically. You might need to call this method before exporting to PDF, only in rare cases where a table appear incorrectly laid out in PDF output.


removeMacros

public void removeMacros()
Removes all macros (the VBA project) from the document.

By removing all macros from a document you can ensure the document contains no macro viruses.


getChildNodes

→ inherited from CompositeNode
public NodeCollection getChildNodes(int nodeType, boolean isDeep)
Returns a live collection of child nodes that match the specified type.

The collection of nodes returned by this method is always live.

A live collection is always in sync with the document. For example, if you selected all sections in a document and enumerate through the collection deleting the sections, the section is removed from the collection immediately when it is removed from the document.

Parameters:
nodeType - A NodeType value. Specifies the type of nodes to select.
isDeep - True to select from all child nodes recursively. False to select only among immediate children.
Returns:
A live collection of child nodes of the specified type.

getChildNodes

→ inherited from CompositeNode
public NodeCollection getChildNodes(int nodeType, boolean isDeep, boolean isLive)
Returns a "live" or "snapshot" collection of child node that match the specified type.

Snapshot collections require less resources than live collections because a snapshot collection of nodes is not updated when the document is changed.

Snapshot collections are useful for tasks, that do not require immediate update of the collection when the document is changed. For example, select all shapes and delete them is more efficient using a snapshot collection.

A live collection is always in sync with the document. For example, if you selected all sections in a document and enumerate through the collection deleting the sections, the section is removed from the collection immediately when it is removed from the document.

Parameters:
nodeType - A NodeType value. Specifies the type of nodes to select.
isDeep - True to select from all child nodes recursively. False to select only among immediate children.
isLive - True to return a live collection; false to return a snapshot collection.
Returns:
A collection of child nodes of the specified type.

getChild

→ inherited from CompositeNode
public Node getChild(int nodeType, int index, boolean isDeep)
Returns an Nth child node that matches the specified type.

If index is out of range, a null is returned.

Parameters:
nodeType - A NodeType value. Specifies the type of the child node.
index - Zero based index of the child node to select. Negative indexes are also allowed and indicate access from the end, that is -1 means the last node.
isDeep - True to select from all child nodes recursively. False to select only among immediate children.
Returns:
The child node that matches the criteria or null if no matching node is found.

selectNodes

→ inherited from CompositeNode
public NodeList selectNodes(java.lang.String xpath)
                    throws org.jaxen.JaxenException
Selects a list of nodes matching the XPath expression.

Only expressions with element names are supported at the moment. Expressions that use attribute names are not supported.

Parameters:
xpath - The XPath expression.
Returns:
A list of nodes matching the XPath query.

selectSingleNode

→ inherited from CompositeNode
public Node selectSingleNode(java.lang.String xpath)
                     throws org.jaxen.JaxenException
Selects the first Node that matches the XPath expression.

Only expressions with element names are supported at the moment. Expressions that use attribute names are not supported.

Parameters:
xpath - The XPath expression.
Returns:
The first Node that matches the XPath query or null if no matching node is found.

appendChild

→ inherited from CompositeNode
public Node appendChild(Node newChild)
                throws java.lang.Exception
Adds the specified node to the end of the list of child nodes for this node.

If the newChild is already in the tree, it is first removed.

If the node being inserted was created from another document, you should use importNode(com.aspose.words.Node, boolean) to import the node to the current document. The imported node can then be inserted into the current document.

Parameters:
newChild - The node to add.
Returns:
The node added.

prependChild

→ inherited from CompositeNode
public Node prependChild(Node newChild)
                 throws java.lang.Exception
Adds the specified node to the beginning of the list of child nodes for this node.

If the newChild is already in the tree, it is first removed.

If the node being inserted was created from another document, you should use importNode(com.aspose.words.Node, boolean) to import the node to the current document. The imported node can then be inserted into the current document.

Parameters:
newChild - The node to add.
Returns:
The node added.

insertAfter

→ inherited from CompositeNode
public Node insertAfter(Node newChild, Node refChild)
                throws java.lang.Exception
Inserts the specified node immediately after the specified reference node.

If refChild is null, inserts newChild at the beginning of the list of child nodes.

If the newChild is already in the tree, it is first removed.

If the node being inserted was created from another document, you should use importNode(com.aspose.words.Node, boolean) to import the node to the current document. The imported node can then be inserted into the current document.

Parameters:
newChild - The Node to insert.
refChild - The Node that is the reference node. The newNode is placed after the refNode.
Returns:
The inserted node.

insertBefore

→ inherited from CompositeNode
public Node insertBefore(Node newChild, Node refChild)
                 throws java.lang.Exception
Inserts the specified node immediately before the specified reference node.

If refChild is null, inserts newChild at the end of the list of child nodes.

Note: InsertBefore could be slower than InsertAfter because it needs to iterate over all nodes from the first child to the reference node.

If the newChild is already in the tree, it is first removed.

If the node being inserted was created from another document, you should use importNode(com.aspose.words.Node, boolean) to import the node to the current document. The imported node can then be inserted into the current document.

Parameters:
newChild - The Node to insert.
refChild - The Node that is the reference node. The newChild is placed before this node.
Returns:
The inserted node.

removeChild

→ inherited from CompositeNode
public Node removeChild(Node oldChild)
                throws java.lang.Exception
Removes the specified child node.

The parent of oldChild is set to null after the node is removed.

Parameters:
oldChild - The node to remove.
Returns:
The removed node.

removeAllChildren

→ inherited from CompositeNode
public void removeAllChildren()
                      throws java.lang.Exception
Removes all the child nodes of the current node.

indexOf

→ inherited from CompositeNode
public int indexOf(Node child)
Returns the index of the specified child node in the child node array. Returns -1 if the node is not found in the child nodes.

getAncestor

→ inherited from Node
public Node getAncestor(java.lang.Class ancestorType)
Gets the first ancestor of the specified type.

The ancestor type matches if it is equal to ancestorType or derived from ancestorType.

Parameters:
ancestorType - The type of the ancestor to retrieve.
Returns:
The ancestor of the specified type or null if no ancestor of this type was found.

remove

→ inherited from Node
public void remove()
           throws java.lang.Exception
Removes itself from the parent.

nextPreOrder

→ inherited from Node
public Node nextPreOrder(Node rootNode)
Gets next node according to the pre-order tree traversal algorithm.
Parameters:
rootNode - The top node (limit) of traversal.
Returns:
Next node in pre-order order. Null if reached the rootNode.

previousPreOrder

→ inherited from Node
public Node previousPreOrder(Node rootNode)
Gets the previous node according to the pre-order tree traversal algorithm.
Parameters:
rootNode - The top node (limit) of traversal.
Returns:
Previous node in pre-order order. Null if reached the rootNode.

toTxt

→ inherited from Node
public java.lang.String toTxt()
            throws java.lang.Exception
Exports the content of the node into a string in TXT (plain text) format.

This method removes field codes and Microsoft Word control characters, uses CrLf combination to mark ends of paragraphs in the resulting string. It produces a different result from getText() which just gets the text from the document without removing field codes or special characters.

Returns:
The content of the node in plain text format.

addNodeChangedEventHandler

public void addNodeChangedEventHandler(NodeChangedEventHandler newListener)
Adds the NodeChangedEventHandler to the list of subscribed listeners of one of Node Changed event.

removeNodeChangedEventHandler

public void removeNodeChangedEventHandler(NodeChangedEventHandler oldListener)
Removes the NodeChangedEventHandler from the list of subscribed listeners of Node Changed event.

See Also:
          Wiki - the home page for the Aspose.Words Product Documentation that includes Programmer's Guide, Knowledge Base and other articles.
          Aspose.Words Support Forum - our preferred method of support.
          Aspose.Words Team - contact Aspose.Words Team.


ASPOSE home