We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to create a new node of any type

How to create a new node of any type before/after a certain node in DOC.

Please help.

I am using Aspose.words API for java version

Thanks & regards

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I think that you can use insertAfter and insertBefore methods. Please see the following link for more information.


Also see the following example.

// Create new document

Document doc = new Document();

// Get first paragraph from document

Paragraph par = doc.getFirstSection().getBody().getFirstParagraph();

// Create new run

Run run1 = new Run(doc, "this is run");

// Add run to paragraph


// Create another run

Run run2 = new Run(doc, "this is another run");

// Insert run2 before run1

run1.getParentNode().insertBefore(run2, run1);

Hope this helps.

Best regards.