I have xml data files that I want to convert to ms word documents. What is the recommended way to do this? Of course I could use the java API and manually build an entire document. But are there other ways similar to how one might render xml using xslt. I read about XMLReader class to do mail merge but that seems to be a .NET implementation only according to online docs. So what are recommended ways to do this. I’d like to also convert the xml data to pdf in future, so some method that could easily be extended to handle that would be good. Thanks.
Hi
Thanks for your inquiry. There is no direct way to convert XML to document. However, you can achieve this. There can be few approaches:
- You can create your own converter, i.e. read your XML using java API and build Document from scratch.
- If your XML contains only data, which should be inserted at the appropriate places in the document. you can try using Mail Merge. In this case, you should create template as described here:
https://docs.aspose.com/words/net/mail-merge-template/
And use IMailMergeDataSource to fill your document with data:
https://reference.aspose.com/words/net/aspose.words.mailmerging/imailmergedatasource/ - You can try converting your XML to RTF using XSLT transformation and then open RTF document using Aspose.Words.
Best regards.
Thanks for the info, so that confirms that the XMLReader api is only available for .NET? I’ll probably use the 2nd method.
Hi
Thanks for your inquiry. XmlReader is standard .NET class, which is used to read XML. In java, you can read XML, for example like described here:
http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
Best regards.