Camunda Model API - Programmatically adding a new Rule to an existing DMN file fails

Camunda BPM: 7.14.0
Camunda Modeler: 4.3.0
Java: 14.0.1 2020-04-14
Java™ SE Runtime Environment: (build 14.0.1+7)
Java HotSpot™ 64-Bit Server VM: (build 14.0.1+7, mixed mode, sharing)

I’m trying to programmatically add a new Rule to an existing DMN file on my local hard drive using a Java Console application.

My code is based on the Excel sheet to a DMN Decision Table Converter project on GitHub - Camunda DMN XLSX.

The code works fine when I try to create a new DMN file from scratch. However, when I try to add a new Rule to an existing DMN file, it fails with the below error message:


Could not convert file: DOM document is not valid
org.camunda.bpm.model.xml.ModelValidationException: DOM document is not valid
	at org.camunda.bpm.model.xml.impl.parser.AbstractModelParser.validateModel(AbstractModelParser.java:170)
	at org.camunda.bpm.model.dmn.Dmn.doValidateModel(Dmn.java:276)
	at org.camunda.bpm.model.dmn.Dmn.doWriteModelToOutputStream(Dmn.java:263)
	at org.camunda.bpm.model.dmn.Dmn.writeModelToStream(Dmn.java:184)
	at eymp.services.ruleengines.PTARuleManager.DMNGenerator.updateDMN(DMNGenerator.java:72)
	at eymp.services.ruleengines.PTARuleManager.DMNGenerator.main(DMNGenerator.java:34)
Caused by: org.xml.sax.SAXParseException; cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://www.omg.org/spec/DMN/20151101/dmn.xsd":rule}'. One of '{"https://www.omg.org/spec/DMN/20191111/MODEL/":rule}' is expected.
	at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
	at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:135)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:511)
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3587)
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1971)
	at java.xml/com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:829)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.beginNode(DOMValidatorHelper.java:276)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:243)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:189)
	at java.xml/com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:108)
	at java.xml/javax.xml.validation.Validator.validate(Validator.java:124)
	at org.camunda.bpm.model.xml.impl.parser.AbstractModelParser.validateModel(AbstractModelParser.java:165)
	... 5 more

I’m new to Camunda and my Java skills are bit rusty. So, not sure if it an issue in my code or a bug in the model API.

I have attached the Java Source file (.txt file) and the test DMN file to this topic for your review. Please help.

DMNGenerator.txt (9.4 KB) GenerateDMN.dmn (1.4 KB)

Thanks,

Any help with this topic, please?

Thanks,