CamelConfig.java@Componentpublic class CamelConfig extends RouteBuilder { @Override public void configure() throws Exception { try { CamelContext context = new DefaultCamelContext(); ConverterRoute route = new ConverterRoute(); route.addRoutesToCamelContext(context); context.start(); Thread.sleep(5000); context.stop(); } catch (Exception exe) { exe.printStackTrace(); } }}ConverterRoute.javapublic class ConverterRoute implements RoutesBuilder { private static final String SOURCE_INPUT_PATH = "file://inbox?fileName=Source.txt"; private static final String SOURCE_OUTPUT_PATH = "file://outbox?fileName=file.xml"; public void addRoutesToCamelContext(CamelContext context) throws Exception { context.addRoutes(new RouteBuilder() { public void configure() { try { DataFormat bindyFixed = new BindyCsvDataFormat(Test.class); from(SOURCE_INPUT_PATH). unmarshal(bindyFixed). marshal(). xstream(). to(SOURCE_OUTPUT_PATH).log("Finished Transformation").end(); } catch (Exception e) { e.printStackTrace(); } } }); }来源.txt55158|11901|234655158|11101|3454Test.java@CsvRecord(separator = "\\|",skipField = true,name = "Test")public class Test { @DataField(pos = 1,name = "ALT_NUM") private BigDecimal ALT_NUM; @DataField(pos = 2,name = "PRTNUM") private BigDecimal PRTNUM; @DataField(pos = 3,name = "UOMCOD") private Integer UOMCOD;}我能够生成包含单个文件中所有字段的 xml 文件。我想要单个 xml 文件中的单个记录。任何人都可以帮助我。输出文件根元素中的标签名称也生成类的包名称。
1 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
您可能可以用来split()
单独处理 csv 记录中的每一行。
from(SOURCE_INPUT_PATH). .split().tokenize(System.lineSeparator()) unmarshal(bindyFixed). marshal(). xstream(). to(SOURCE_OUTPUT_PATH).log("Finished Transformation").end();
添加回答
举报
0/150
提交
取消