I copied the usage of the fromXml and toXml functions from here: https://github.com/bpmn-io/bpmn-moddle. In the original xml, definitions is all lowercase, in the xmlStrUpdated the first letter of both definitions and process is uppercase. What is the reason for that and is there a way to configure it to be lowercase?
Thanks in advance!
Can you provide more context? What did you copy where and how are you using it?
I copied:
import BpmnModdle from ‘bpmn-moddle’;
const moddle = new BpmnModdle();
const xmlStr =
‘<?xml version="1.0" encoding="UTF-8"?>’ +
'<bpmn2:definitions xmlns:bpmn2=“http://www.omg.org/spec/BPMN/20100524/MODEL” ’ +
'id=“empty-definitions” ’ +
‘targetNamespace=“http://bpmn.io/schema/bpmn”>’ +
‘</bpmn2:definitions>’;
const {
rootElement: definitions
} = await moddle.fromXML(xmlStr);
// update id attribute
definitions.set(‘id’, ‘NEW ID’);
// add a root element
const bpmnProcess = moddle.create(‘bpmn:Process’, { id: ‘MyProcess_1’ });
definitions.get(‘rootElements’).push(bpmnProcess);
// xmlStrUpdated contains new id and the added process
const {
xml: xmlStrUpdated
} = await moddle.toXML(definitions);
xmlStrUpdated looks like this: <?xml version="1.0" encoding="UTF-8"?>
<bpmn2:Definitions xmlns:bpmn2=“http://www.omg.org/spec/BPMN/20100524/MODEL” id=“NEW ID” targetNamespace=“http://bpmn.io/schema/bpmn”><bpmn2:Process id=“MyProcess_1” /></bpmn2:Definitions>
- I am using a customSchema which extends bpmn:Process and bpmn:Definitions, probably this is the reason for the uppercase
bpmn-moddle will serialize elements as uppercase by default. If you want them to be lowercase you need to add that information to your extension:
{
"name": "Foo",
"uri": "http://foo.com",
"prefix": "foo",
"types": [ ... ],
"xml": {
"tagAlias": "lowerCase"
}
}
Thanks for the answer. Since XML is case sensitive and elements/attributes have to be in the same form as defined in the schema files, is there a reason behind this implementation?
It allows you to define your moddle types uppercase (e.g. Definitions
) and still have them serialized lowercase (e.g. definitions
).