Inject multiple XML records [message #776878] |
Mon, 09 January 2012 12:56  |
Eclipse User |
|
|
|
Hi,
Can an XML injection accept multiple XML documents as input? My problem is to correlate multiple XML input documents (based on same metamodel) into lesser number of output XML documents based on some parameters in the input. For this I need to input multiple XML files that need to be correlated to the ATL transformation. How can I do this?
[Updated on: Mon, 09 January 2012 13:20] by Moderator Report message to a moderator
|
|
|
Re: Inject multiple XML records [message #778211 is a reply to message #776878] |
Wed, 11 January 2012 17:39   |
Eclipse User |
|
|
|
I tried out the XML injection of multiple XML documents, and it works up to this point:
1. Source XML Documents -> Source XML Ecore Documents
2. Source XML Ecore Documents -> Source XMI Documents
3. Source XMI Documents -> Target XMI Documents
4. Target XMI Documents -> Target XML Ecore Documents
But the last step:
5. Target XML Ecore Documents -> Target XML Documents
which is using the AM3 XML Extraction tool, is only extracting one (the first) XML Document, and not all.
Could anyone help me with this? When I go through the source code of the XML Extractor it does seem to extract more than one root document, so why is it not working?
|
|
|
|
Re: Inject multiple XML records [message #778262 is a reply to message #778213] |
Thu, 12 January 2012 02:57   |
Eclipse User |
|
|
|
Thanks Sylvain,
does that mean that I use Java code to extract the individual XML documents after this step:
4. Target XMI Documents -> Target XML Ecore Documents
Java: Extract individual XML Ecore Documents
5. Iterate: One XML Ecore Document -> One Target XML
When I go throuhg code of the XML Extractor, there is a similiar piece of code in the "extract" function which seems to be doing the same thing (pasted below). Or I am mistaken? I dont mind using Java to extract, but I want to be sure there is no API already existing :
Extract:
public void extract(IModel sourceModel, OutputStream target, Map<String, Object> options)
throws ATLCoreException {
PrintStream outStream = new PrintStream(new BufferedOutputStream(target));
outStream.println("<?xml version = '1.0' encoding = 'ISO-8859-1' ?>");
EMFModel xmlModel = (EMFModel) sourceModel;
EClass rootClass = (EClass) xmlModel.getReferenceModel().getMetaElementByName("Root");
Set<EObject> rootElements = xmlModel.getElementsByType(rootClass);
serializeContent(
rootElements.iterator().next(),
xmlModel, outStream, "");
outStream.close();
}
|
|
|
Re: Inject multiple XML records [message #778272 is a reply to message #778262] |
Thu, 12 January 2012 05:21  |
Eclipse User |
|
|
|
It turns out there is a bug in the XMLExtractor code, which I fixed by changing the code as below:
Extract:
public void extract(IModel sourceModel, OutputStream target, Map<String, Object> options)
throws ATLCoreException {
PrintStream outStream = new PrintStream(new BufferedOutputStream(target));
outStream.println("<?xml version = '1.0' encoding = 'ISO-8859-1' ?>");
EMFModel xmlModel = (EMFModel) sourceModel;
EClass rootClass = (EClass) xmlModel.getReferenceModel().getMetaElementByName("Root");
Set<EObject> rootElements = xmlModel.getElementsByType(rootClass);
//Inserted code
Object eArray = rootElements.toArray();
for (int i=0;i<rootElements.size();i++){
//serializeContent(
//rootElements.iterator().next(),
//xmlModel, outStream, "");
serializeContent( (EObject)eArray[i],xmlModel,outStream,"");
}
outStream.close();
}
[Updated on: Thu, 12 January 2012 05:22] by Moderator Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03233 seconds