[ad_1]
I am trying to generate XSD(XML schema) from the XML body and below is the code I have. But I am not able to generate. What would be the alternative solution?
public ResponseEntity<Object> generateXmlSchema(@RequestBody String xml)
throws IOException, ParseException, CustomErrorException {
try {
XmlParser xmlP = new XmlParser();
xmlP.parse(xml);
XsdGen gen = new XsdGen();
JSONObject xsdSchema = new JSONObject();
File xmlFile = new File(xmlPath);
xmlFile.createNewFile();
PrintWriter writer = new PrintWriter(xmlFile);
writer.write(xml);
writer.flush();
writer.close();
XsdGen result = gen.parse(new File(xmlPath));
String resultObj = "`" + result + "`";
xsdSchema.put("xsdSchema", resultObj);
return ResponseEntity.ok().body(xsdSchema);
} catch (Exception e) {
log.info("error occured in generateXmlSchema: " + e.getMessage());
throw new CustomErrorException(e.getMessage());
}
}
[ad_2]