on 10-22-2012 10:56 AM
Hi,
Can we pass value to the node using grahical mapping?
If not kindly suggest how to achieve the requirement.
Regards,
Praveen
Hi Praveen,
you can map the value to node in graphical mapping but you need to define complex XSD type, which needs to implement in External definition.
Please refer GS1 standard XSD for more information.
http://www.gs1.org/docs/gsmp/xml/3_0/BMS_Package_Item_Data_Notification_r3p0p0_i1p0p0_20Dec2011.zip
Regards,
Harish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Praveen,
Might be my response is bit late as I have seen your query today only. Please refer this Blog.
You can pass value to a node in graphical mapping as well.
Write a small udf with the following snippet.
StructureNode structurenode = ((StructureNode) container.getParameter("STRUCTURE_NODE"));
structurenode.setPostValue(input);
return structurenode.toString();
For your requirement, other way around is also available. Just check and follow the standard mapping provided by SAP in which you can find a way to simulate on how to pass a value to node instead of using above little udf. of course, an udf is mandatory in any case.
Hope I addressed your query.
Thanks
Sridhar
P.S. if you have invalid XML input then it pops up with error such as XML invalid. for Eg: J & K value is being passed to node. it should be either J and K, or J & K.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
why would you want to do that ? value to a node ?
Can you show an example of how the node should look like after that ?
(or are you talking about an attribute?)
Thank you,
Regards,
Michal Krawczyk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Praveen,
You need java mapping to resolve this issue. Lets take an example of input xml as shown below
<comment>
<att>
hi
</att>
please see
<att1> hello</att1>
SCN is great
</comment>
and you need to map the text elements to target field which are defined. I have guessed the target to look like as shown below
<?xml version="1.0" encoding="UTF-8" standalone="no"?><comment><att>
hi
</att><TextNode0>
please see
</TextNode0><att1> hello</att1>
<TextNode1> SCN is great </TextNode1>
</comment>
I have generated the names of the target field in my mapping code such as "TextNode0" etc.You can pass the names of the nodes as array of strings as per your requirement.
Here is the sample java code
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
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.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
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;
public class DOMParser2 extends AbstractTransformation{
/**
* @param args
*/
static String payload="";
public void execute(InputStream in, OutputStream out)throws Exception
{
Document document;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(in);
Document docOut=builder.newDocument();
Node root=document.getDocumentElement();
Element targetRoot;
Node tChild;
targetRoot=(Element)docOut.createElement(root.getNodeName());
//targetRoot.setAttribute("xmlns:ns1","http://www.ABC.com.au/salesrepexport");
NodeList l=root.getChildNodes();
Node temp;
String nodeNames="TextNode";
int j=0;
for(int i=0;i<l.getLength();++i)
{
if(l.item(i).getNodeType()==3)
{
String str=l.item(i).getTextContent();
int len=str.length(),k;
for(k=0;k<len;++k )
{
if(str.charAt(k)==10 || str.charAt(k)==9|| str.charAt(k)==32)
{
continue;
}
else
{
break;
}
}
if(k>=len)
{
continue;
}
if(str.length()<=0)
{
continue;
}
Node temp1;
temp=docOut.createElement(nodeNames+j);
j++;
temp1=docOut.importNode(l.item(i),true);
temp.appendChild(temp1);
tChild=temp;
}
else
{
tChild=docOut.importNode(l.item(i),true);
}
targetRoot.appendChild(tChild);
}
docOut.appendChild(targetRoot);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transform = tf.newTransformer();
transform.transform(new DOMSource(docOut), new StreamResult(out));
}
@Override
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
// TODO Auto-generated method stub
try {
this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Hope this resolves your problem. Just recompile the code and try using in mapping. I assumed you are working in PI 7.1 or above version else java code needs changes.
Regards
Anupam
User | Count |
---|---|
84 | |
10 | |
10 | |
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.