Thanks for your prompt reply,
Actually my scenario is : I need to write the footer content alone in a separate HTML.
When I tried the following code I got the out.html with unwanted extra p nodes.
Document doc = new Document("onlyFooter.doc");
// Create temporary document
Document tempDoc = new Document();
// Get child nodes from header
NodeCollection footerChildren = doc.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY).getChildNodes();
// Loop through all nodes inside header
for (int i = 0; i < footerChildren.getCount(); i++)
{
// Import node
Node dstNode = tempDoc.importNode(footerChildren.get(i), true, ImportFormatMode.KEEP_SOURCE_FORMATTING);
tempDoc.getFirstSection().getBody().appendChild(dstNode);
}
// Save temporary document in HTML fromat
tempDoc.save("out.html", SaveFormat.HTML);
Here I have attached the DOC.