Overview
XML Tooling based on EMF (EXML) used to loading/saving XML with EMF. You can process XML content without pre-defined ecore models in EMF.
Simple EMF Model
Easy Loading
- Standard XML Supported without schema.
- Comment and CData supported.
- Very simple data structure with Element and Attribute.
- Only need 3 lines of code.
EXMLResourceFactoryImpl fac = new EXMLResourceFactoryImpl();
XMLResource resource = (XMLResource) fac.createResource(uri);
HashMap<String, Object> options = new HashMap<String, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
resource.load(inputStream, options);
Saving XML
- Saving to standard XML files.
- Comment and CData supported.
EXMLResourceFactoryImpl fac = new EXMLResourceFactoryImpl();
Resource resource = fac.createResource(URI.createFileURI("Sample-save.xml"));
EXDocument doc = EXMLFactory.eINSTANCE.createDocument();
EXElement root = EXMLFactory.eINSTANCE.createElement();
root.setName("Company");
EXAttribute nameAttr = EXMLFactory.eINSTANCE.createAttribute();
nameAttr.setName("name");
nameAttr.setValue("Soyatec");
root.getAttributes().add(nameAttr);
for (int i = 0; i < 5; i++) {
EXElement child = EXMLFactory.eINSTANCE.createElement();
child.setName("Employee");
child.getText().add("Robot" + i);
root.getElements().add(child);
}
doc.setElement(root); resource.getContents().add(doc);
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
<?xml version="1.0" encoding="ASCII"?>
<Company name="Soyatec">
<Employee>Robot0</Employee>
<Employee>Robot1</Employee>
<Employee>Robot2</Employee>
<Employee>Robot3</Employee>
<Employee>Robot4</Employee>
</Company>