The type Node has a function toString: Node | Aspose.Words for Java
One of SaveOptions subclasses is OoxmlSaveOptions: OoxmlSaveOptions | Aspose.Words for Java
One of the SaveFormats for OoxmlSaveOptions is FLAT_OPC: SaveFormat | Aspose.Words for Java
Here is the function I’m trying to write:
private void printDocument(com.aspose.words.Document aDoc) {
Node n = aDoc.getFirstChild();
SaveOptions sv = new OoxmlSaveOptions();
sv.setSaveFormat(SaveFormat.FLAT_OPC);
sv.setPrettyFormat(true);
String nodeText = "";
try {
nodeText = n.toString(sv);
} catch (Exception ex) {
nodeText = ex.getMessage();
}
System.out.println(nodeText);
}
All that gets printed is “Exporting fragments of a document in this format is not supported.”
However, the decompiled code for the Node toString function looks like this:
public String toString(SaveOptions saveOptions) throws Exception {
Object var10000;
switch(saveOptions.getSaveFormat()) {
case 50:
var10000 = new zzZX0((HtmlSaveOptions)saveOptions);
break;
case 70:
var10000 = new zzYTP((TxtSaveOptions)saveOptions);
break;
default:
throw new IllegalStateException("Exporting fragments of a document in this format is not supported.");
}
return ((zzZRC)var10000).zzZt(this);
}
So, the documentation seems to be wrong. You can only print a Node via HTML or TXT. You seem to be unable to print an arbitrary Node’s XML contents.
This feature would be VERY useful for debugging purposes so that I can see what actual XML content Aspose is inserting into a document as it’s happening.