We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words Java Merge Nested Region error A location step was expected following the '/' or '//' token

Dear sirs!
I doesn’t have enough experince with XML.
I tried to make mail merge to nested region. And I have error: XPathExpressionException
A location step was expected following the ‘/’ or ‘//’ token.

My code is:

public void testXML()
{
    DocumentBuilder db;
    try
    {
        db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        org.w3c.dom.Document xmlData = db.parse("C:/Temp/qmDocument.xml");
        Document doc = new Document("C:/Temp/qma_tittle_xml.docx");
        doc.getMailMerge().execute(new XmlMailMergeDataTable(xmlData, "Document"));
        doc.save("C:/Temp/qmDocOut.docx");
    }
    catch (ParserConfigurationException e)
    {
        e.printStackTrace();
    }
    catch (SAXException e)
    {
        e.printStackTrace();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

Class XmlMailMergeDataTable i’ve copied from aspose documentation
It work for simple mail merging, But not nested region. Template doc file and xml in attachments

What’s wrong!
Thank you advance, Boris Shuster

Sorry, I have read more attentive…
I found recommendation to use XmlMailMergeDataSet instead XmlMailMergeDataTable and
executeWithRegions instead execute…

db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document xmlData = db.parse("C:/Temp/qmDocument.xml"); 
Document doc = new Document("C:/Temp/qma_tittle_xml.docx");
doc.getMailMerge().setUseNonMergeFields(true);
doc.getMailMerge().executeWithRegions(new XmlMailMergeDataSet(xmlData));
doc.save("C:/Temp/qmDocOut.docx");

but still not result… I have no exception, but I have empty merge fields…
Is something wrong in XML?
I would be grateful for advice…
Boris

If anybody have orders.xml and template.doc to this example (see below) it would be usefull to understanding. Please attach it, if possible

https://github.com/aspose-words/Aspose.Words-for-Java

Now I’m understanding, why aspose support not in a hurry to answer a questions. This encourages developers to look for solutions and study the documentation (in my country says “to smoke a manuals” )
I’ve solved the problem by MustachTemplateSyntax.
Furhermore. It helps me to understand where was error in XML file…
Thank support personal for examples

It would be very interesting to know is it possible to use merge with regions mutually with MailMergeFormFields (not XML)?

Hi Boris,

Thanks for your inquiry. It’s great you were able to find what you were looking for. Please let us know any time you have any further queries.

You can find related resources/documents in following section:
resources/com/aspose/words/examples

Secondly, to learn more about mail merge with regions feature of Aspose.Words, please refer to the following articles:

Mail Merge with Regions Explained
How to Execute Mail Merge with Regions
How to Use Nested Mail Merge Regions

Best regards,