We have to deal with documents where some XPath mapping is missing, but which should considered as a warning not an exception.
It seems SDT isMapped property is not correctly considered in that case.
In the attached example document the XmlMapping API shows the following properties:
SDT IsMapped: false
SDT Tag: RevisionIssueDate
XPath: /ns0:adress[1]/ns0:RevisionIssueDate[1]
Store Item: com.aspose.words.CustomXmlPart@1eb439a
The actual XPath Target does not exist which then leads to the exception on save.
But since IsMapped is false, I think this should not be counted as an error?
It would be great if instead a warning is logged or some configuration would allow the handling.
Is there any option to control log level btw?
It appears you are facing an issue where saving a document results in an exception due to missing XPath mappings, even when the IsMapped property of the Structured Document Tag (SDT) is set to false. This can be frustrating, especially when you expect it to be treated as a warning rather than an error.
Currently, Aspose.Words does not provide a built-in option to change the error handling behavior for missing XPath mappings to warnings. However, you can implement a workaround by checking the IsMapped property before attempting to save the document. If it is false, you can log a warning message and either skip the save operation or handle it as needed.
Aspose.Words does not offer a direct API to control logging levels for such exceptions, so you may need to create your own logging mechanism to capture these warnings.
Here’s a simple example of how to check the IsMapped property before saving:
Document doc = new Document("your-document.docx");
StructuredDocumentTag sdt = (StructuredDocumentTag) doc.getChild(NodeType.StructuredDocumentTag, 0, true);
if (!sdt.getXmlMapping().getIsMapped()) {
System.out.println("Warning: SDT is not mapped. Skipping save operation.");
} else {
doc.save("output.docx");
}
This approach allows you to manage the situation more gracefully without encountering exceptions.
@stgross
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-28668
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.