on 08-08-2012 3:27 PM
Hi All,
Please check the below requirement and let me know how to achieve it.
Source:
A1
|------INVITEM1
|------INVIPART1
|------INVIMATER1
|------INVITEM11
|------INVIPART11
|------INVIMATER11
A2
|------INVITEM2
|------INVIPART2
|------INVIMATER2
Target:
A1
|------INVITEM1
|------INVIPART1
|------INVIMATER1
|------INVITEM11
|------INVIPART11
|------INVIMATER11
A2
|------INVITEM2
|------INVIPART2
|------INVIMATER2
No fields are common in the parent and child nodes. I need to achieve this through graphical mapping.Please help.
Regards,
Nutan
Hi Nutan,
Paste your source and Traget structure defined in PI based on that someone can help you.
use split value function with value change option .
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raj,
By SplitbyValue the Target structure is coming as below:
Source:
A1
|------INVITEM1
|------INVIPART1
|------INVIMATER1
|------INVITEM11
|------INVIPART11
|------INVIMATER11
|------INVIMATER12
A2
|------INVITEM2
|------INVIPART2
Target:
A1
|----INVITEM1
|-------INVIPART1
|-------INVIMATER1
|-----INVITEM11
|-------INVIPART11
|-------INVIMATER11
A2
|-----INVITEM2
|-------INVIPART2
|-------INVIMATER12
In the source Under A1 after INVITEM11 there are two INVIMATER11 and INVIMATER12, so in the target both the INVIMATER11 and INVIMATER12 should have come under INVITEM11, but as you can see it's just splitting by value and moving into next node of A2--INVITEM2, which is incorrect.
My aim is achieve this:
whenever INVITEM is coming in source a new node should be created in target and the below INVIPART and INVIMATER should be added under the INVITEM node as in the source.
If INVITEM is twice in source under one context then it should be created twice in target under one context and INVIMATER and INVIPART should follow the context of INVITEM as in the target.
Regards,
Nutan
Hi Nutan,
I doubt that your requirement will be achieved by Graphical mapping .With following java code you can get your output.
Call below class from transform() method . Hope this code will help you
mport java.io.OutputStream;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class Nutan extends DefaultHandler {
private OutputStream out;
String chars;
Nutan (OutputStream out)
{this.out= out;}
public void print(String str) throws SAXException
{
try{
out.write(str.getBytes());
out.flush();
}
catch(Exception e){
e.printStackTrace();
}
}
public void characters(char[] ch, int start, int length)
throws SAXException {
chars = new String(ch,start, length);
print(chars);
//System.out.println(chars);
// TODO Auto-generated method stub
}
public void endDocument() throws SAXException {
print("</nutan>");
// TODO Auto-generated method stub
}
public void endElement(String uri, String localName, String name1)
throws SAXException{
//super.endElement(uri, localName, name);
if(name1.equals("A1"))
{}
if(name1.equalsIgnoreCase("INVIPART1"))
{
print("</INVIPART1>");
}
if(name1.equalsIgnoreCase("INVIMATER1"))
{
print("</INVIMATER1>");
print("</INVITEM1>");
}
if(name1.equalsIgnoreCase("INVIPART11"))
{
print("</INVIPART11>");
}
if(name1.equalsIgnoreCase("INVIMATER11"))
{
print("</INVIMATER11>");
print("</INVITEM11>");
print("</A1>");
}
}
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
print("<nutan>");
//System.out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
}
public void startElement(String uri, String localName, String name,
Attributes atts) throws SAXException {
//System.out.println(uri);
//System.out.println(localName);
System.out.println(name);
if(name.equals("A1"))
{
print("<A1>");
}
if(name.equalsIgnoreCase("INVITEM1"))
{
print("<INVITEM1>");
}
if(name.equalsIgnoreCase("INVIPART1"))
{
print("<INVIPART1>");
}
if(name.equalsIgnoreCase("INVIMATER1"))
{
print("<INVIMATER1>");
}
if(name.equalsIgnoreCase("INVITEM11"))
{
print("<INVITEM11>");
}
if(name.equalsIgnoreCase("INVIPART11"))
{
print("<INVIPART11>");
}
if(name.equalsIgnoreCase("INVIMATER11"))
{
print("<INVIMATER11>");
}
}
}
Regards
Hari.
Hi Hari,
The nodes can repeat many times. I check the source data, it's having sequence number along with each node as below:
Source:
A1
|------INVITEM1 (sequence no 1)
|------INVIPART1 (2)
|------INVIMATER1 (3)
|------INVITEM11 (4)
|------INVIPART11 (5)
|------INVIMATER11 (6)
|------INVIMATER12 (7)
A2
|------INVITEM2 (1)
|------INVIPART2 (2)
so I hope to achieve target the sequence no can be used. I can compare INVITEM and INVIPART sequence no.
please check the below code:
here var1 = sequence no of INVITEM and var2 = sequence no of INVIPART.
for(int i =0;i<2;)
{
int x = i; i++;
for(int j =0; j<3;j++)
{
if((var1[x]<var2[j]) && (var1[i]>var2[j]))
{
result.addValue(var2[j]);
i --;
}
else
{
result.addContextChange();
result.addValue(var2[j]);
}
}
}
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.