on 06-23-2013 1:28 PM
Hi,
This is my input XML.
` <?xml version="1.0" encoding="UTF-8"?>
<queryResponse>
<result>
<done>true</done>
<queryLocator xsi:nil="true" />
<records xsi:type="sf:OpportunityLineItem">
<sf:Id>00kS0000005RwheIAC</sf:Id>
<sf:SAP_QuoteItemNumber__c>000001</sf:SAP_QuoteItemNumber__c>
</records>
<records xsi:type="sf:OpportunityLineItem">
<sf:Id>00kS0000005RwhfIA </sf:Id>
<sf:SAP_QuoteItemNumber__c>000002</sf:SAP_QuoteItemNumber__c>
</records>
<records xsi:type="sf:OpportunityLineItem">
<sf:Id>00kS0000005RwhgIAC</sf:Id>
<sf:SAP_QuoteItemNumber__c>000003</sf:SAP_QuoteItemNumber__c>
</records>
<records xsi:type="sf:OpportunityLineItem">
<sf:Id>00kS0000005RwhhIAC</sf:Id>
<sf:SAP_QuoteItemNumber__c>000004</sf:SAP_QuoteItemNumber__c>
</records>
<records xsi:type="sf:OpportunityLineItem">
<sf:Id>00kS0000005RwhiIAC</sf:Id>
<sf:SAP_QuoteItemNumber__c>000005</sf:SAP_QuoteItemNumber__c>
</records>
<records xsi:type="sf:OpportunityLineItem">
<sf:Id>00kS0000005RwhjIAC</sf:Id>
<sf:SAP_QuoteItemNumber__c>000006</sf:SAP_QuoteItemNumber__c>
</records>
<size>6</size>
</result>
</queryResponse>`
I have to read this XML and split into 6 XMLper records.
so output should look like
1st XML
`
<?xml version="1.0" encoding="UTF-8"?>
<records xsi:type="sf:OpportunityLineItem">
<sf:Id>00kS0000005RwheIAC</sf:Id> <sf:SAP_QuoteItemNumber__c>000001</sf:SAP_QuoteItemNumber__c>
</records>`
2nd xml
` <?xml version="1.0" encoding="UTF-8"?>
<records xsi:type="sf:OpportunityLineItem">
<sf:Id> 00kS0000005RwhfIAC</sf:Id> <sf:SAP_QuoteItemNumber__c>000002</sf:SAP_QuoteItemNumber__c>
</records>`
3rd XML
` <?xml version="1.0" encoding="UTF-8"?>
<records xsi:type="sf:OpportunityLineItem">
<sf:Id>00kS0000005RwhgIAC</sf:Id>
<sf:SAP_QuoteItemNumber__c>000003</sf:SAP_QuoteItemNumber__c>
</records>`
.....
....
so on upto 6th xml.
Please help , how to get it.
I dont think you need Java mapping for this because even though you are going to split record in to multiple times but the straucture is same but then content is difference ,only challening is building mapping logic.
Use multi mapping design and use combination of useOneAs many/split by value combination.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raja,
this is small part of my parent java mapping. i am getting the XML dynamically and the number of fields and fieldnames in the record are dynamic and i will know those only @ runtime.
So actualy i have to do this in Java mapping only.
Actualy i have a SAX parser written where i will feeding in each record. it is workign when i am feeding one record but not working for multiple record.So my idea is to split the record and send the data one by one and finaly construct the final output.
Hi,
You can use graphical mapping for this requirement. Should be achievable easily by multi-mapping.
Ambrish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ambarish, i cannot because my requirement is different - because
this is small part of my parent java mapping. i am getting the XML dynamically and the number of fields and fieldnames in the record are dynamic and i will know those only @ runtime.
So actualy i have to do this in Java mapping only.
Actualy i have a SAX parser written where i will feeding in each record. it is workign when i am feeding one record but not working for multiple record.So my idea is to split the record and send the data one by one and finaly construct the final output.
If your sender system is file content conversion then you can configure recorset per message value 1 to achieve this. BTW, what is your sender message structure?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
You want to create different XML files pertaining to each "record" node in the source ? If yes, then check below link:
http://wiki.sdn.sap.com/wiki/display/XI/Multi-Mapping+using+Java+Mapping
Thanks
Amit Srivastava
Sam
I have just provided you the approach...BTW u never mentioned in your post that u need a exact java code to implement your logic (Atleast i can't able to see that...), so the foremost important thing while posting a thread on SDN is that you have to be precise - a basic rule ?
Now coming to the java logic, i don't see any complication in implementing this logic..Using a dom parser a simple java mapping can be cretaed.
Thanks
Amit Srivastava
Sam,
Don't worry i am not boiling...
Yes, indeed the wiki is just showing how to implement multimapping concept using java mapping and using that u have to build your code, and no one on SDN will ever post a wiki/blogs for these specific and easy requirements...
Using above wiki i have implemented below code in 20 mins so if u would have given a try i am sure you might have also implemented the same:
package test;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class Multimapping extends AbstractTransformation
{
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
System.out.println ("1");
try {
this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream()) ;
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void execute(InputStream in, OutputStream out)throws StreamTransformationException, ParserConfigurationException, SAXException, IOException
{
// TODO Auto-generated method stub
try
{
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder =factory.newDocumentBuilder();
/*input document in form of XML*/
Document doc = builder.parse(in);
/*document after parsing*/
Document docOut=builder.newDocument();
TransformerFactory tf=TransformerFactory.newInstance();
Transformer transform=tf.newTransformer();
//Document doc;
Element root= docOut.createElement("Messages");
docOut.appendChild(root);
root.setAttribute("xmlns:sm","http://sap.com/xi/XI/SplitAndMerge");
System.out.println (root);
Element root1= docOut.createElement("Messages");
root.appendChild(root1);
NodeList units= doc.getElementsByTagName("records");
for(int i=0;i<units.getLength();i++)
{
System.out.println (units.getLength());
Node units1= doc.getElementsByTagName("records").item(i);
root1.appendChild(docOut.adoptNode(units1.cloneNode(true)));
System.out.println (root1.toString());
}
transform.transform(new DOMSource(docOut), new StreamResult(out));
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[]) throws StreamTransformationException
{
try
{
InputStream in=new FileInputStream ("C:\\Users\\Desktop\\Test.xml");
FileOutputStream out=new FileOutputStream("C:\\Users\\Desktop\\Output.xml");
Multimapping g=new Multimapping();
g.execute(in, out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Thanks
Amit Srivastava
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.