cancel
Showing results for 
Search instead for 
Did you mean: 

issues on multiplemapping

Former Member
0 Kudos

one xml source structure is like this

<E_Students>

<Student>

<ID>1</ID>

<Name>Michael Tang</Name>

</Student>

<Student>

<ID>2</ID>

<Name>Aegean Yin</Name>

</Student>

</E_Students>

the other xml source structure is like this

<C_Students>

<Student>

<ID>2</ID>

<Gender>Female</Gender>

</Student>

<Student>

<ID>1</ID>

<Gender>Male</Gender>

</Student>

</C_Students>

the target xml structure is like this

<Students>

<Student>

<ID>1</ID>

<Name>Michael Tang</Name>

<Gender>Male</Gender>

</Student>

<Student>

<ID>2</ID>

<Name>Aegean Yin</Name>

<Gender>female</Gender>

</Student>

<Students>

the solution I used is multiptle mapping, like this

E_Students.student.id->Students.student.id

E_Students.student.Name->Students.student.Name

C_Students.student.Gender->Students.student.Gender

these two source xml structures may not order by ID, now they must be linked by ID, but when mapped, it did not function, just mapped by sequence, not by ID. who can help me? it is very urgent.

If anyone can provide me other solutions, I will appreciate:)

Message was edited by: Spring Tang

correct xml structure error

Accepted Solutions (1)

Accepted Solutions (1)

former_member187339
Active Contributor
0 Kudos

Hi,

Some doubts !!

1) Why the student tag empty? In all the three structures...

2) Does ID and name comes in pair?

3) Same for ID and gender.

Regards

Suraj

Former Member
0 Kudos

I correct my error on xml structure, thanks for your reply:)

ID and Name come in pairs, ID and Gender also come in pair

Message was edited by: Spring Tang

Former Member
0 Kudos

Hi Spring,

Please try the following:

<b>Source Structure1:</b><?xml version="1.0" encoding="UTF-8"?>

<E_Students> Occurrence 1...1

|----<Student> Occurrence 1...Unbounded

|----


<ID> Occurrence 1...1

|----


<Name> Occurrence 1...1

<b>Source Structure2:</b>

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

<C_Students> Occurrence 1...1

|----<Student> Occurrence 1...Unbounded

|----


<ID> Occurrence 1...1

|----


<Gender> Occurrence 1...1

<b>Target Structure:</b>

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

< Students> Occurrence 1...1

|----<Student> Occurrence 1...Unbounded

|----


<ID> Occurrence 1...1

|----


<Name> Occurrence 1...1

|----


<Gender> Occurrence 1...1

<b>Mapping rules:</b>

E_Students.student(with context as E_Students)--->Students.student

E_Students.student.id(with context as E_Students)>sort(with lexico graphical case insensitive)>splitbyvalue(each value)->Students.student.id

E_Students.student.id(with context as E_Students)---\

-


|>sortByKey(with lexico graphical case insensitive)>splitbyvalue(each value)->Students.student.Name

E_Students.student.Name(with context as E_Students)-/

E_Students.student.id(with context as E_Students)>sort(with lexico graphical case insensitive)>splitbyvalue(each value)---\

-


|>StringEquals|if\

C_Students.student.id(with context as C_Students)>sort(with lexico graphical case insensitive)>splitbyvalue(each value)---/

-


|---|>C_Students.student.Gender->Students.student.Gender

C_Students.student.id(with context as C_Students)-----\

-


|>sortByKey(with lexico graphical case insensitive)>splitbyvalue(each value)----


|then/

C_Students.student.Gender(with context as C_Students)-/

<b>TextPreview of mapping:</b>

/ns0:Messages/ns0:Message1/Students/Student=/ns0:Messages/ns0:Message1/E_Students/Student=

/ns0:Messages/ns0:Message1/Students/Student/ID=SplitByValue(sort(/ns0:Messages/ns0:Message1/E_Students/Student/ID=))

/ns0:Messages/ns0:Message1/Students/Student/Name=SplitByValue(sortByKey(/ns0:Messages/ns0:Message1/E_Students/Student/ID=, /ns0:Messages/ns0:Message1/E_Students/Student/Name=))

/ns0:Messages/ns0:Message1/Students/Student/Gender=ifWithoutElse(stringEquals(SplitByValue(sort(/ns0:Messages/ns0:Message1/E_Students/Student/ID=)), SplitByValue(sort(/ns0:Messages/ns0:Message2/C_Students/Student/ID=))), SplitByValue(sortByKey(/ns0:Messages/ns0:Message2/C_Students/Student/ID=, /ns0:Messages/ns0:Message2/C_Students/Student/Gender=)))

<b>Test data:</b>

<b>Input:</b>

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

<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">

<ns0:Message1>

<E_Students>

<Student>

<ID>1</ID>

<Name>Michael Tang</Name>

</Student>

<Student>

<ID>2</ID>

<Name>Aegean Yin</Name>

</Student>

</E_Students>

</ns0:Message1>

<ns0:Message2>

<C_Students>

<Student>

<ID>2</ID>

<Gender>Female</Gender>

</Student>

<Student>

<ID>1</ID>

<Gender>Male</Gender>

</Student>

</C_Students>

</ns0:Message2>

</ns0:Messages>

<b>OutPut:</b>

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

<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">

<ns0:Message1>

<Students>

<Student>

<ID>1</ID>

<Name>Michael Tang</Name>

<Gender>Male</Gender>

</Student>

<Student>

<ID>2</ID>

<Name>Aegean Yin</Name>

<Gender>Female</Gender>

</Student>

</Students>

</ns0:Message1>

</ns0:Messages>

Regards,

KNS Kumar.

Former Member
0 Kudos

I appreciate if you provide more clearer info on "Gender" node mapping:). the text style is so mixed that i understand somewhat difficult. thanks

Former Member
0 Kudos

sort and sortbykey will have the <b>lexico graphical case insensitive</b>

SpliByValue has <b>each value</b>

id and gender has context as E_Students or C_Students

E_Students.student.id->sort->splitbyvalue-\

-


|-stringequals-|if..\

C_Students.student.id->sort->splitbyvalue-/

-


|---|>Students.student.Gender

C_Students.student.id----


\

-


|sortBYKEY->splitbyvalue---|then/

C_Students.student.Gender-/

Former Member
0 Kudos

when apply your mapping, it still does not function right. but I add one node function "removeContexts" before every sort & sortbykey node function after the element. it succeeds. I don't know why. Thanks a lot.

Former Member
0 Kudos

Hi Spring,

If you can observe i mentioned that <b>"id and gender has context as E_Students or C_Students"</b>. This basicaly does what you are doing using removeContexts.

If your requirement is met please close the thread.

Regards,

KNS Kumar.

Former Member
0 Kudos

Hi,kumar

Thanks a lot for your work:)

Former Member
0 Kudos

I still don't know which I need to use removeContexts, which don't need to use it.If anyone provide me more info, I will appreciate

former_member187339
Active Contributor
0 Kudos

Hi,

Generally mapping is done based on context.

eg:

<root>

---<stud>

-


<id> 1 </id>

-


<Name> A </Name>

---</stud>

---<stud>

-


<id> 2 </id>

-


<Name> B </Name>

---</stud>

---<stud>

-


<id> 3 </id>

-


<Name> C </Name>

---</stud>

Now here if you take <b>id</b> it is wrt <stud>, so the queue will be

1

---

2

---

3

---

If you change the context to root then the queue will be

1

2

3

-


You might have noted the difference...

Now if you have chosen the context as <stud> and after that you have given removeContext then it will be having the same meaning as that of the second queue.

eg:

1 -


1

---

2 => removeContext => 2

---

3 -


3

--- ---

ie no matter whatever be the context it will be removed, and the values will be wrt root node..

Regards

Suraj

Former Member
0 Kudos

the two source xml and one target xml structure is very big. there are many mapping between them, do I need to add one sort & sortKey function to every mapping?

Message was edited by: Spring Tang

Former Member
0 Kudos

Hi,Kumar

my two source xml and target xml structure is very large, I don't want to use sort to mapping every element. is there any solution. I don't need sort

former_member187339
Active Contributor
0 Kudos

Hi,

Then you have to go for user defined function :

First do this

Student(context Student)--Student

ID (context Student)-- ID

Name (context Student) -- Name

Now for gender write this function

here

ID (context Employee)

C_ID (context C_Employee)

Gender (context C_Employee)

<b>

int i = 0, j=0;

for (i=0;i<ID.length;i++)

{

for (j=0;j<C_ID.length;j++)

{

if (ID<i>.equals(C_ID[j]))

result.addValue(" "+Gender[j]);

}

}</b>

Regards

Suraj

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Spring

That would be better if you export your mapping to the file

Then it is much easier to reproduce your use case and provide you with some solution.

Best regards

Dmitry