i was using 23.1 version not trying to upgrade to 25.3 but my old class are throwing errors
In Aspose.Words, if you’re looking for an alternative to the getChildNodes()
method to retrieve all nodes within the body of a document, you can utilize the getChildNodes(NodeType, true)
method. This method allows you to specify the type of nodes you want to retrieve and whether to include child nodes.
For example, if you want to get all paragraph nodes in the body, you can do the following:
Document doc = new Document("your-document.docx");
CompositeNode body = doc.getFirstSection().getBody();
NodeCollection paragraphs = body.getChildNodes(NodeType.PARAGRAPH, true);
for (Node paragraph : paragraphs) {
System.out.println(paragraph.getText());
}
In this code snippet:
- We first load the document.
- We access the body of the first section.
- We then retrieve all paragraph nodes within that body using
getChildNodes(NodeType.PARAGRAPH, true)
. - Finally, we iterate through the collection and print the text of each paragraph.
This approach should work seamlessly in version 25.3 and help you avoid errors that may arise from upgrading from version 23.1. If you encounter any specific issues during the upgrade, feel free to ask for further assistance!
yes but i need list of all the node in a body regardless of their node type
@surenderr CompositeNode.getChildNodes(NodeType.ANY, false)
is an exact replacement of CompositeNode.getChildNodes()
property.
In older versions CompositeNode.getChildNodes()
property internally calls the above mentioned method. So each time you use CompositeNode.getChildNodes()
property, CompositeNode.getChildNodes(NodeType.ANY, false)
method is called that might have performance impact. So it was decided to remove CompositeNode.getChildNodes()
property from public API.