# Doubt XML Composition in Object RM Openehr transformation **Category:** [Implementation](https://discourse.openehr.org/c/implem/39) **Created:** 2021-06-22 12:31 UTC **Views:** 667 **Replies:** 6 **URL:** https://discourse.openehr.org/t/doubt-xml-composition-in-object-rm-openehr-transformation/1656 --- ## Post #1 by @luiz_Minelli Hello everyone, I need to transform an XML composition into RM Object, but the examples I find don't work for me. I need to understand how I can perform this conversion performance. I found this library https://github.com/openEHR/java-libs/tree/master/xml-binding/src/test/java/org/openehr/binding But it doesn't recognize that my XML is a composite, as the tag names are not explicitly stated with the attributes, see example [habits.xml|attachment](upload://ecuIqtslMj6LFrHRY80xwE3tKDA.xml) (5.1 KB) I'm working with java 8 and this is an example I made based on library tests! String xml; try { xml = loadXml(); XMLBinding binding = new XMLBinding(); COMPOSITION xobj = CompositionDocument.Factory.parse(xml).getComposition(); Object rmObj = binding.bindToRM(xobj); System.out.println("TEST"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } --- ## Post #2 by @pablo Your XML is not valid openEHR XML, you need to validate first against the schema. For instance, there are no elements in openEHR XML like these: - Habits - Alcohol_use> You can use the toolkit to generate valid XMLs https://toolkit.cabolabs.com/ --- ## Post #3 by @luiz_Minelli Hello, I discovered the problem, the problem is that the conversion does not occur because the XML is based entirely on the template (The xml is not incorrect), but that I would need a TDO of the template to be able to convert definitively into an object In the template design tool by OCEAN contains this conversion only in C#, would you know if there is a tool to transform the template into JAVA(8)? since it creates with all inheritance correctly, the template contains several different areas and names, it would be almost impossible to create a manual object I've been working with openehr for about 4 to 5 months and I feel very difficult to find tools (Specifically libraries) that help me in development, object and class specifications are magnificent and visualization tools like (archetype design), but I miss indications to help in the development, it is very difficult to find answers, the easiest way is to come to the forum --- ## Post #4 by @pablo Hi Luiz, the XML is wrong against the canonical openEHR XSD, you need to have an XSD to know if it is correct or not. For instance: 1. the namespace "oe" is not defined and it is used, see the context element 2. in the canonical XSD there is no element named "Habits" or "Alcohol_use" or "Consumption_Summary", all elements that appear in your XML So maybe the XML is valid against some XSD, but it is not valid against the canonical XSD https://specifications.openehr.org/releases/ITS-XML/Release-1.0.2/components/ALL If you use the toolkit mentioned above you can generate XMLs from OPTs and validate them against the canonical XSD. I'm sure the Java implementation parser works with canonical XML, but won't work with the XML you provided. Hope that helps. --- ## Post #5 by @luiz_Minelli Now I get it, I really appreciate your help. I will try to convert the XML to XMLCanonical, is there a library that already does this? --- ## Post #6 by @pablo Please check the Toolkit mentioned above. --- ## Post #7 by @luiz_Minelli Solution: For those who need to do this, it is necessary to have the template XSD at hand In the code you will need to traverse the XSD looking for each matching name to convert your XML and put the Archetype node id By doing this conversion and following the openehr validation rules you will be able to perform the conversion Thank you Pablo! --- **Canonical:** https://discourse.openehr.org/t/doubt-xml-composition-in-object-rm-openehr-transformation/1656 **Original content:** https://discourse.openehr.org/t/doubt-xml-composition-in-object-rm-openehr-transformation/1656