on 12-31-2013 4:24 PM
Hello PI Experts,
Needed help with message mapping, I have multiple source fields with multiple structures and need to pass it to a single target field. What is the best way to achieve this? Can anybody share any idea or perhaps UDF code? Can this be achieved using 'Return as XML' in graphical message mapping?
Thanks,
John
Please check the below doc for 'Retrun as Xml' use case -
If your requirement is simillar then you can go for it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
>>I have multiple source fields with multiple structures and need to pass it to a single target field.
U want ur source structure to be returned as xml string or xml structure??
“Return as XML” – returns the source node as XML structure (due to the presence of Xml definition tag <?xml version="1.0" encoding="UTF-8"?> ) which eventually create xml nodes beneath ur target element instead of assigning xml string value to it.
In case you want to pass input structure as a xml string to ur target field then u have to remove XML declaration before assigning source node to target element.
Something like:
Source Node (Return as XML)
Constant (<?xml version="1.0" encoding="UTF-8"?>)------Replace String --- Target Field
Constant()
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
John I recommend UDF or Java Mapping.
Try the code provide fro Virkrant.
Kind regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Concat all fields and use UDF
Suppose if i have 2 fields Field 1 & Field 2
UDF code you can use as below
for (int i=0;i<var1.length;i++)
{
s=s.concat(var1[i] );
}
result.addValue(s);
I am not sure if i understood your problem correctly.Let us know more details
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Vikrant,
I tried the udf code you gave but getting errors when checking. Here is my source and target structure:
Source Structure:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="urn:mmtest" xmlns="urn:mmtest" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="MT_Source" type="DT_Source"/>
<xsd:complexType name="DT_Source">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/VersionID">8eaac9e8724811e3c9c30000003aec92</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="Lvl1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Field1" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field2" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field3" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Lvl2">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Field1" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field2" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field3" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Lvl3">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Field1" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field2" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field3" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Lvl4">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Field1" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field2" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field3" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Lvl5">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Field1" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field2" type="xsd:string" minOccurs="0"/>
<xsd:element name="Field3" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
Target Structure:
<xsd:schema targetNamespace="urn:mmtest" xmlns="urn:mmtest" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="MT_Target" type="DT_Target"/>
<xsd:complexType name="DT_Target">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/VersionID">fd6f61cc724711e398e50000003aec92</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="strg2xml" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Errors in UDF:
cannot find symbol symbol : method concat(java.lang.String) location: class java.lang.String[] s=s.concat(var1[i] );
cannot find symbol symbol : variable result location: class com.sap.xi.tf._MM_Test1_ result.addValue(s);
Vikrant,
Thanks for your help.
I tried doing the way put in your reply but getting the output with values only, does not give like <field1>value</field1>, etc. This is not the output expected. Please see below:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_Target xmlns:ns0="urn:mmtest"><strg2xml>onetwothreefourfivesixseveneightnineteneleventwelvethirteenfourteenfifteen</strg2xml></ns0:MT_Target>
Hi John,
Can you provide additional details. May be sample xml and target structure.
You can use concat function and appened all the fields and send it to one target field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.