Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to keep the namespace prefix when saving a new model
How to keep the namespace prefix when saving a new model [message #1852015] Mon, 25 April 2022 19:31 Go to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 192
Registered: July 2009
Senior Member
Hi,

I have a problem with the XML output format generated by my EMF Resource Factory.
The result of the .xml file is technical ok, but I want to keep the namespace prefix in the tags:

My generated output looks like this:

<?xml version="1.0" encoding="ASCII"?>
<bpmn2:Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100501/MODEL-XMI"
  xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100501/DI-XMI"
  expressionLanguage="java" exporter="demo">
  <diagrams xsi:type="bpmndi:BPMNDiagram"/>
  <process xsi:type="bpmn2:Process"/>
</bpmn2:Definitions>


what I would need is something like this where each xml tag has contains the namespace prefix and not the xsi:type info:

....
  <bpmndi:diagrams />
  <bpmn2:process />
</bpmn2:Definitions>


My code generating the file output looks like this

        URI uri = URI.createURI("src/test/resources/openbpmn-empty.bpmn");
        Bpmn2ResourceFactoryImpl resFactory = new Bpmn2ResourceFactoryImpl();
        Resource resource = resFactory.createResource(uri);
        resource.getContents().add(......);
       ....
            Map options = new HashMap();
            options.put(XMLResource.OPTION_SAVE_TYPE_INFORMATION,  true);
        resource.save(null);


I tried now nearly every option but I did not found the trick.

Can someone help me?

====
Ralph
Re: How to keep the namespace prefix when saving a new model [message #1852016 is a reply to message #1852015] Mon, 25 April 2022 19:38 Go to previous messageGo to next message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 192
Registered: July 2009
Senior Member
Could it be that I need to use eAnnotations in my ecore file, which I currently have not defined? Something like this:

      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="process"/>
        <details key="namespace" value="http://www.omg.org/spec/BPMN/20100501/MODEL"/>
      </eAnnotations>

Re: How to keep the namespace prefix when saving a new model [message #1852017 is a reply to message #1852016] Mon, 25 April 2022 19:43 Go to previous message
Ralph Soika is currently offline Ralph SoikaFriend
Messages: 192
Registered: July 2009
Senior Member
Ah! Yes - adding the eAnnotation with the namespace did the trick. Now my XML tag is containing the namespace - when I disable the OPTION_SAVE_TYPE_INFORMATION

    options.put(XMLResource.OPTION_SAVE_TYPE_INFORMATION, false);


result looks now like this:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100501/MODEL" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100501/MODEL http://www.omg.org/spec/BPMN/20100501/MODEL-XMI" expressionLanguage="java" exporter="demo">
  <diagrams/>
  <bpmn2:process/>
</bpmn2:Definitions>


So the eAnnotation seems to be more important than I expected.....
Previous Topic:Weird maven-dependency-plugin copy problem with emf.common.2.19
Next Topic:how to load other project's ecore resource
Goto Forum:
  


Current Time: Thu Apr 25 07:50:14 GMT 2024

Powered by FUDForum. Page generated in 0.02487 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top