Handling of Mixed Content Element in XI

 

What is Mixed Content in XML?
An element that can have both text values and subelements, as its Content.
For eg.
<element>
       This is text.
       <innerElement> inside inner element </innerElement>
       Here again plain text.
       <innerElement> has value </innerElement>
       <innerElement> has different value </innerElement>
</element>
Now the tag “<element>” has mixed Content.
One of my scenario had this mixed content element and was required to be handled in XI.
The first problem was how to create the datatype. In the Data Type creation once an element is given Type, subelement cant be created for this. If subelement is created the parent automatically becomes complex type.
Inserting subelement for an element having global type, results as shown in screenshot below.
image
Assigning type to complex element, results as shown in screenshot below.
image
The problem was solved by creating “xsd” of the input structure and importing it as external definition. Similarly the output structure was also imported.
The scenario was finished using these external definitions and Graphical Mapping. The entire scenario worked fine without any errors, but the output payload didn't had text values of the mixed content element.
For e.g
<element>
       This is text.
       <innerElement> inside inner element </innerElement>
</element>
The text value in above example is “This is text”.
This issue can be solved in two methods.
First Method:
This was a round about solution that solved my problem initially.
In this method, the problem was handled by use of File Adapter Modules.
Steps
1. Get the input payload inside the adapter module.
2. Parse it using any XML parser that can handle mixed content.
3. Convert the mixed content element to normal complex type element by putting the text values into another subelement. Something like this
<element>
       <newElement>This is text.</newElement>
       <innerElement> inside inner element </innerElement>
       <newElement>Here again plain text. </newElement>
       <innerElement> has value </innerElement>
       <innerElement> has different value </innerElement>
</element>
4. Then finally, the data types are created according to the payload that the module provides.
Second Method:
Another simple solution to the problem is to use JAVA Mapping. In this case, the entire problem can be taken care in the Mapping itself. XSLT mapping can also solve this problem.
Finally the scenario was successfully finished, by using external definitions (xsd) for datatypes and JAVA Mapping as mapping technique.
This seems to be a strange scenario and this blog is to share it with the developer community.

SAP Developer Network SAP Weblogs: SAP Process Integration (PI)