下面列出了怎么用org.eclipse.emf.ecore.xmi.util.XMLProcessor的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Load the XML file with a given XML schema. This method should be used in
* conjuction with the nullary constructor.
*
* @param schema
* @param file
* @return
*/
public boolean load(File schema, File file) {
// Create a new XMLProcessor to be used in creating
// and persisting XML Resources
try {
xmlProcessor = new XMLProcessor(URI.createFileURI(schema.getAbsolutePath()));
} catch (SAXException e) {
logger.error(getClass().getName() + " Exception!", e);
return false;
}
return load(file);
}
protected String toString(final Organization organization) throws IOException {
final XMLResource resource = createResourceFromOrganization(organization);
final XMLProcessor processor = new OrganizationXMLProcessor();
final Map<String, Object> options = new HashMap<>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
options.put(XMLResource.OPTION_XML_VERSION, "1.0");
options.put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
return processor.saveToString(resource, options);
}
/**
* The constructor, takes a Java file pointing to the XML schema model.
*
* @param file
* The XML Schema
*/
public EMFComponent(File file) {
super();
// Initialize class data
iceEMFTree = new EMFTreeComposite();
xmlResource = new XMLResourceImpl();
// Make sure we have a valid File object.
if (file != null) {
// Create a new XMLProcessor to be used in creating
// and persisting XML Resources
try {
xmlProcessor = new XMLProcessor(URI.createFileURI(file.getAbsolutePath()));
} catch (SAXException e) {
logger.error(getClass().getName() + " Exception!", e);
}
if (xmlProcessor != null) {
// Get the package containing the model
EPackage ePackage = (EPackage) xmlProcessor.getEPackageRegistry().values().toArray()[0];
// Get the TreeIterator to walk over the elements
TreeIterator<EObject> tree = ePackage.eAllContents();
while (tree.hasNext()) {
// Get the Element
EObject obj = tree.next();
// We only care about EClass instances bc those
// are the nodes of the tree.
if (obj instanceof EClass) {
EClass eClass = (EClass) obj;
// Add the new EMFTreeComposite corresponding to the
// current
// EClass instance to the mapping
if ("DocumentRoot".equals(eClass.getName())) {
// This will give us a root node, and the
// constructor
// will take care of constructing possible exemplar
// children nodes.
iceEMFTree = new EMFTreeComposite(eClass);
break;
}
}
}
}
}
return;
}