cancel
Showing results for 
Search instead for 
Did you mean: 

Recursive structure - complex mapping issue

Former Member
0 Kudos

I have a recursive structure involved mapping requirement. here is the issue simplified...

Source is a details about person which has a element called father which itself is of the type person. Target is just a list or person with n father attribute. Target has to have all the persons, father and father's father with no limitation. Below are the XSDs and XML for source and target. I know I can do this in java or abap mapping or even xslt, but is it possible to achieve this in the mapping too? Any help will be appreciated and rewarded.

No where in the forum or blog I could find a sample mapping.

<b>Sorry for the long post</b>

Thanks

<b>Source XML</b>


<?xml version="1.0" encoding="UTF-8"?>

<ns0:PersonsMT xmlns:ns0="http://xyz.com/scratchpad">
   <Persons>
      <Person>
         <Name>Smith</Name>
         <Height>22</Height>
         <Father>
            <Name>Paul</Name>
            <Height>23</Height>
            <Father>
                   <Name>Sr Paul</Name>
                   <Height>23</Height>
            <Father/>
         </Father>
         </Father>
      </Person>
      <Person>
         <Name>Brad</Name>
         <Height>22</Height>
         <Father>
            <Name>Luke</Name>
            <Height>23</Height>
            <Father/>
         </Father>
      </Person>
   </Persons>
</ns0:PersonsMT>

<b>Expected output:</b>


<?xml version="1.0" encoding="UTF-8"?>
<ns0:PersonsListOutputMT xmlns:ns0="http://xyz.com/scratchpad">
<Persons>
	<Person>
		<Name>Smith</Name>
		<Height>22</Height>
	</Person>
	<Person>
		<Name>Paul</Name>
		<Height>23</Height>
	</Person>
	<Person>
		<Name>Sr Paul</Name>
		<Height>23</Height>
	</Person>
	<Person>
		<Name>Brad</Name>
		<Height>22</Height>
	</Person>
	<Person>
		<Name>Luke</Name>
		<Height>23</Height>
	</Person>
</Persons>
</ns0:PersonsListOutputMT>

<b>Source Schema:</b>

<i>Message Type: PersonsMT</i>


<?xml version="1.0" encoding="ISO-8859-1"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://xyz.com/scratchpad" targetNamespace="http://xyz.com/scratchpad">
	<xsd:element name="PersonsMT" type="PersonsDT" />
	<xsd:complexType name="PersonDT">
		<xsd:annotation>
			<xsd:appinfo source="http://sap.com/xi/TextID">
			34bfd3107ba111dcc4e600188b447e47
			</xsd:appinfo>
		</xsd:annotation>
		<xsd:sequence>
			<xsd:element name="Name" type="xsd:string">
				<xsd:annotation>
					<xsd:appinfo source="http://sap.com/xi/TextID">
					56bf53607b7d11dca285000f1ffb32b9
					</xsd:appinfo>
				</xsd:annotation>
			</xsd:element>
			<xsd:element name="Height" type="xsd:string">
				<xsd:annotation>
					<xsd:appinfo source="http://sap.com/xi/TextID">
					56bf53617b7d11dcc38a000f1ffb32b9
					</xsd:appinfo>
				</xsd:annotation>
			</xsd:element>
			<xsd:element name="Father" type="PersonDT">
				<xsd:annotation>
					<xsd:appinfo source="http://sap.com/xi/TextID">
					56bf53627b7d11dccc3d000f1ffb32b9
					</xsd:appinfo>
				</xsd:annotation>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
	<xsd:complexType name="PersonsDT">
		<xsd:annotation>
			<xsd:appinfo source="http://sap.com/xi/TextID">
			34bd89227ba111dcc2fa00188b447e47
			</xsd:appinfo>
		</xsd:annotation>
		<xsd:sequence>
			<xsd:element name="Persons" maxOccurs="unbounded">
				<xsd:annotation>
					<xsd:appinfo source="http://sap.com/xi/TextID">
					9915e6707b7d11dcadc7000f1ffb32b9
					</xsd:appinfo>
				</xsd:annotation>
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="Person" type="PersonDT">
							<xsd:annotation>
								<xsd:appinfo source="http://sap.com/xi/TextID">
								9915e6717b7d11dc8f84000f1ffb32b9
								</xsd:appinfo>
							</xsd:annotation>
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
</xsd:schema>

<b>Target Schema:</b>

<i>Message Type: PersonsListOutputMT</i>



<?xml version="1.0" encoding="ISO-8859-1"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://xyz.com/scratchpad" targetNamespace="http://xyz.com/scratchpad">
	<xsd:element name="PersonsListOutputMT" type="PersonListOutputDT" />
	<xsd:complexType name="PersonListOutputDT">
		<xsd:annotation>
			<xsd:appinfo source="http://sap.com/xi/TextID">
			380defd37ba511dcb27400188b447e47
			</xsd:appinfo>
		</xsd:annotation>
		<xsd:sequence>
			<xsd:element name="Persons" maxOccurs="unbounded">
				<xsd:annotation>
					<xsd:appinfo source="http://sap.com/xi/TextID">
					edfc5ae07b9e11dca41b001422795f21
					</xsd:appinfo>
				</xsd:annotation>
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="Person">
							<xsd:annotation>
								<xsd:appinfo source="http://sap.com/xi/TextID">
								edfc5ae17b9e11dcb186001422795f21
								</xsd:appinfo>
							</xsd:annotation>
							<xsd:complexType>
								<xsd:sequence>
									<xsd:element name="Name">
										<xsd:annotation>
											<xsd:appinfo source="http://sap.com/xi/TextID">
											edfc5ae27b9e11dc9e93001422795f21
											</xsd:appinfo>
										</xsd:annotation>
									</xsd:element>
									<xsd:element name="Height">
										<xsd:annotation>
											<xsd:appinfo source="http://sap.com/xi/TextID">
											edfc5ae37b9e11dcb5e1001422795f21
											</xsd:appinfo>
										</xsd:annotation>
									</xsd:element>
								</xsd:sequence>
							</xsd:complexType>
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
</xsd:schema>

Message was edited by:

xi_ted

Message was edited by:

xi_ted

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Can you please cheack your generated source and target WSDL. According to me, you need some modification in that. You can generate xd using xmlspy.

context will be the problem in graphical mapping as well as xslt. So best is to go for java mapping for this.

In graphical mapping you can generate required target provided you know max hirarchy for father. In that case its possible to use graphical mapping.

-Kavita

Former Member
0 Kudos

Yes I came to the same conclusion, to use Java mapping.

Thanks latika and kavita.

Former Member
0 Kudos

hi,

in message mapping this can be achieved by duplicating target structures in mapping. duplicate target "Person".

the first node to be mapped to source "Person"

secnd to source father with appropriate context.

jus try this... hope it helps.

regards,

latika.

Former Member
0 Kudos

i can't because i don't know how many times I will need to duplicate. it is dynamic.

Thanks

Former Member
0 Kudos

ya rite.

the other option that comes to my mind is a UDF that takes care of occurences and contexts itself and again takes ur java code rite? )

regards,

latika.

Former Member
0 Kudos

yeah. i don't mind UDF but I guess it becomes very complex and ugly

maybe for this scenario mapping tool is not suitable.

thanks