Hi ,
I’m trying to use conditional mailmerge fields (if-statements) with " ; (") in my xml source.
This leads to the following error:
Elementname: D
Attribut: Name="""INDEX:0
java.lang.IllegalStateException
at com.aspose.words.zzZ99.zznj(Unknown Source)
at com.aspose.words.zzYqX.zzWgd(Unknown Source)
at com.aspose.words.zzYqX.getText(Unknown Source)
at com.aspose.words.zzYqX.zzcp(Unknown Source)
at com.aspose.words.zzYqX.zzZOL(Unknown Source)
at com.aspose.words.zzYoi.zzWH7(Unknown Source)
at com.aspose.words.zzYoi.zzZeH(Unknown Source)
at com.aspose.words.zzTk.zzz4(Unknown Source)
at com.aspose.words.zzTk.zzYsF(Unknown Source)
at com.aspose.words.zzTk.zzW3B(Unknown Source)
at com.aspose.words.zzTk.zzWhE(Unknown Source)
at com.aspose.words.zzTk.zzVOs(Unknown Source)
at com.aspose.words.zzTk.zzZa5(Unknown Source)
at com.aspose.words.zzTk.zzWB7(Unknown Source)
at com.aspose.words.zzTk.zzYBC(Unknown Source)
at com.aspose.words.zzZo.zzWPL(Unknown Source)
at com.aspose.words.zzZo.zzY7o(Unknown Source)
at com.aspose.words.zzZo.zzWPL(Unknown Source)
at com.aspose.words.MailMerge.zzWPL(Unknown Source)
at com.aspose.words.MailMerge.executeWithRegions(Unknown Source)
at aspose_master.aspose_app.App.handleRegions(App.java:75)
When Mailmerge function is executed it throws the error, if I use &apos ; instead it throws no error, but I need to work with the xml source file that already uses " ; in attribute values.
I have attached a short example mvn project with both xml cases and a junit test, just run mvn test -e
to see the error on the " xml source.
@bennetpe Thank you for reporting the problem to us. For a sake of correction it has been logged as WORDSNET-23893. We will keep you informed and let you know once it is resolved.
As a workaround, you can modify your data source like the following (add \ before quot;):
thank you for your quick reply.
I’ve tried your workaround advice and the error does not appear anymore, but it seems not correct escaping the quot, because it is rendered after mailmerge like " in the pdf document.
I’ve changed the xml source like above directly and also tried to iterate over DOM Nodes and replaced attribute nodes values containing the " ; - char sequence.
Both result in the same output, any advice what I’m doing wrong here?
Thank you very much for the hint, this works now as expected if only one quote is in xml.
But usally I have words with opening and closing " ; in xml
like:
// Workaround for " bug in xml attributes
if (element.getAttributes().item(x).getNodeValue().contains("\"")) {
String input = element.getAttributes().item(x).getNodeValue();
String escapedQuot = input.replaceAll("\"", "\\\\\"");
System.out.println("Escaped String "+ escapedQuot);
element.setAttribute(
element.getAttributes().item(x).getNodeName(),
escapedQuot);
}
I get the escaped value: \" Some Text \" wich seems correct, however in pdf after mailmerge the first \" is correct merged into " whereby the second enclosing (and all following) \" merged into \".
So the recived value in pdf looks like: "Some Text\" instead of "Some Text".
This does not thrown an exception, but both are rendered as escaped \". I have added this information into the created defect. Unfortunately, I did not manage to find a workaround for this. Our development team will analyze the issue and we provide you more information.