如何通过数据映射器在mule

时间:2015-06-26 06:21:16

标签: mule mule-component

我有一个XML如下:

<?xml version='1.0' encoding='UTF-8'?>
<ns2:trigger xmlns:ns2="http://www.someurl.com/" id="1001">
    <changes>
        <change id="5" userName="12334">
            <UserField name="Organisation">Organisation 1</UserField>
            <UserField name="Age"/>
            <UserField name="First name">1</UserField>
        </change>
        <change id="1" userName="abc">
            <UserField name="Organisation">Organisation 1</UserField>
            <UserField name="Age"/>
            <UserField name="First name">Name</UserField>
        </change>
        <change employeeId="123" id="2" userName="hr"> 
            <UserField id="8" name="Organisation">Firma AS</UserField>
            <UserField id="33" name="Age"/>
            <UserField id="2" name="Last name">HR</UserField>
        </change>
        <change employeeId="q123" id="16" userName="Ashish">
           <UserField name="Organisation">Organisation 1</UserField>
            <UserField name="Age"/>
            <UserField name="Last name">Ashish Singh</UserField>
        </change>
    </changes>
</ns2:trigger>

我想从上面的XML生成另一个XML,如下所示:

<DATA>
    <SAVE>
        <EMPLOYEE>
            <FIRST_NAME>1</FIRST_NAME>
            <AGE></AGE>
            <ORGANIZATION>Organisation 1</ORGANIZATION>
        </EMPLOYEE>
        <EMPLOYEE>
             <FIRST_NAME>Name</FIRST_NAME>
            <AGE></AGE>
            <ORGANIZATION>Organisation 1</ORGANIZATION>
        </EMPLOYEE>
        <EMPLOYEE>
            <LAST_NAME>HR</LAST_NAME>
            <AGE></AGE>
            <ORGANIZATION>Organisation 1</ORGANIZATION>
        </EMPLOYEE>
        <EMPLOYEE>
             <LAST_NAME>Ashish Singh</LAST_NAME>
            <AGE></AGE>
            <ORGANIZATION>Organisation 1</ORGANIZATION>
        </EMPLOYEE>

    </SAVE>
</DATA>

我研究过数据映射器并尝试获取所需的XML,但我无法实现它。我正在做这个映射,它给了我以下输出:

mapping

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <save>
    <employee>
      <name>Organisation</name>
    </employee>
    <employee>
      <name>Age</name>
    </employee>
    <employee>
      <name>First name</name>
    </employee>
    <employee>
      <name>Organisation</name>
    </employee>
    <employee>
      <name>Age</name>
    </employee>
    <employee>
      <name>First name</name>
    </employee>
    <employee>
      <name>Organisation</name>
    </employee>
    <employee>
      <name>Age</name>
    </employee>
    <employee>
      <name>Last name</name>
    </employee>
    <employee>
      <name>Organisation</name>
    </employee>
    <employee>
      <name>Age</name>
    </employee>
    <employee>
      <name>Last name</name>
    </employee>
  </save>
</data>

请告诉我如何通过数据映射器完成。

1 个答案:

答案 0 :(得分:1)

Your target mapping structure looks incorrect to me. You will need to amend or re-create this.

I'd suggest you re-create the metadata based on the sample XML you've provided above. In your DataMapper window, above the output mapping box, hit the little wand button and select Re-Create Metadata. Then you want to generate it from a sample file and use the XML you've provided.