csv到xml:不确定在Mule ESB中执行此操作的最佳方法 [英] csv to xml: not sure the best way to do it in Mule ESB

查看:65
本文介绍了csv到xml:不确定在Mule ESB中执行此操作的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是M子的新手,所以请多多包涵.我收到了以下CSV文件:

I'm new to Mule, so bear with me. I have the following CSV file that I receive:

Company1,2,123 Street,Winchester,UK
"000010","CHRISTINE","I","HAAS","A00","3978","1995-01-01","PRES",18,"F","1963-08-24",152750.00
"000020","MICHAEL","L","THOMPSON","B01","3476","2003-10-10","MANAGER",18,"M","1978-02-02",94250.00

第一行标头包含公司信息以及CSV文件中的记录数(员工数)(标头中的第二个参数).

The first line, header, contains company info plus the number of records (number of employees) in CSV file (second parm in the header).

现在我需要将其转换为以下XML:

Now I need to convert it to the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<tns:employeedata xmlns:tns="http://coxb.test.legstar.com/payrollemployee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://coxb.test.legstar.com/payrollemployee PayrollEmployee.xsd ">
  <tns:employeecount>2</tns:employeecount>
  <tns:employeelist>
    <tns:employees>
      <tns:employeenumber>000010</tns:employeenumber>
      <tns:firstname>CHRISTINE</tns:firstname>
      <tns:middleinitial>I</tns:middleinitial>
      <tns:surname>HAAS</tns:surname>
      <tns:department>A00</tns:department>
    </tns:employees>
    <tns:employees>
      <tns:employeenumber>000020</tns:employeenumber>
      <tns:firstname>MICHAEL</tns:firstname>
      <tns:middleinitial>L</tns:middleinitial>
      <tns:surname>THOMPSON</tns:surname>
      <tns:department>B01</tns:department>
    </tns:employees>
  </tns:employeelist>
</tns:employeedata>

我可以很容易地在没有第一行(标题)的情况下转换此文件.我的问题是如何处理标题并提取/转换"employeecount".

I could easily transform this file without the first line (header). My problem is how to process the header and extract/transform "employeecount".

任何帮助将不胜感激.

推荐答案

最简单的方法是使用

The easiest way to do this is to use DataMapper. Set the input to CSV (using a sample CSV) and the output to XML (using your XSD or a sample XML).

一旦进入映射视图,请单击"employeecount"字段.您会看到一个可以输入表达式的区域.您可以使用未记录的参数$in.0.__id,该参数将包含记录计数.请注意,这仅适用于CSV文件.

Once you're in the mapping view, click on your employeecount field. You'll see an area where you can enter an expression. There is a non-documented parameter $in.0.__id which you can use which will contain the record count. Note that this will only work for CSV files.

关于如何跳过第一行,DataMapper默认情况下会执行此操作.

Regarding how to skip the first line, DataMapper does this by default.

这篇关于csv到xml:不确定在Mule ESB中执行此操作的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆