Words. Validate template before save

Good day!

We really want the creation of a document not to break when passing an empty set of placeholders.
However, not always your library allows this.
In particular, the IMG tag with an empty placeholder gives an error …

Now we have problems with the fact that we cannot validate the template that is sent to us, because we obviously do not know what kind of placeholders will be there.
Ideally, if the template is correctly formed with the correct set of placeholders, it will also be correctly formed with the empty set of placeholders.

Maybe you already have other ways to check the template for correctness?

Some test if you need:

Error:

java.lang.IllegalStateException: Tag ‘image’ is not well-formed. An expression providing image data should return a byte array, a string, or an instance of type ‘class asposewobfuscated.zz7M’ or ‘class java.awt.image.BufferedImage’.

@rubcs,

We have logged your problem in our issue tracking system. Your ticket number is WORDSNET-17809 . We will further look into the details of this problem and will keep you updated on the status of the linked issue.

@rubcs,

After further investigation, we found that this is actually not a bug in Aspose.Words. You use a missing type member, but do not apply ReportBuildOptions.ALLOW_MISSING_MEMBERS, so the exception is thrown as per description of this constant. This is an expected behavior.

However, if ReportBuildOptions.ALLOW_MISSING_MEMBERS is applied, then a missing field value is treated as a null literal. A null value cannot be used to insert an image, so the engine throws another exception then. This is an expected behavior either, but we can make the engine to be less restrictive in this scenario by ignoring null values, so that you could achieve what you need.

Instead, we consider this as an enhancement rather than a bug. We are working on this issue further and will keep you posted on further updates.

The issues you have found earlier (filed as WORDSNET-16496) have been fixed in this update

@rubcs,

Regarding WORDSNET-17809, it is to update you that we have changed the behavior regarding expressions evaluated to null values for image and doc tags. From now, if such an expression is evaluated to null, image or document insertion simply does not occur and no exception is thrown. However, you use the missing object members in your original scenario. So, you need to apply ReportBuildOptions.ALLOW_MISSING_MEMBERS in addition to make the engine treat missing object members as null literals. Then everything should work as he expected.