Reading of XML content from String and generate PDF

Dear Team,

I am working on a requirement where in one of the java Application, as a POST request the application is receiving the XML content in the form of a String.

Here I have written the code to convert the String Data into an InputStream and passing the data into “document parser”. But the parser is not recognizing the inputstream content.

Example Code:

@RequestMapping(value = "/doc/example", method = {RequestMethod.GET, RequestMethod.POST})

public void generateEXAMPLEDOCUMENT(
@RequestParam(value = "inputData") String inputData,
HttpServletResponse response, HttpServletRequest request) {
InputSource inSource = new InputSource();
try {
//inputData is the XML content which is passed as String to this method
//Converting the String inputData into XML Stream
inSource.setCharacterStream(new StringReader(inputData));
} catch (Exception e) {
}
Document doc = new Document();
// Use DocumentBuilder from the javax.xml.parsers package and
// Document
// class from the org.w3c.dom package to read
// the XML data file and store it in memory.
javax.xml.parsers.DocumentBuilder db = DocumentBuilderFactory
.newInstance().newDocumentBuilder();
// Parse the XML data.
// org.w3c.dom.Document xmlData = db.parse(inSource);
…
…
…

Kindly help me in providing some inputs to proceed further.

Thanks and Regards

Pradeep

Hi Pradeep,

Thanks for your inquiry. Your query seems not to be related to Aspose.Words API. Please make sure that your xml is correct.

Could you please attach your xml here for testing? We will investigate the issue on our side and provide you more information.

It seems that you are using mail merge feature of Aspose.Words. We suggest you please use DataSet.readXml method and pass the DataSet/DataTable to mail merge engine. Hope this helps you.

DataSet ds = new DataSet();
ds.readXml(MyDir + "in.xml");