根据你的问题,我尝试对此进行一些研究。请检查是否对您有帮助。
\n\n这是要转换的源 edi 文件:
\n\nHDR*1*0*59.97*64.92*4.95*Wed Nov 15 13:45:28 EST 2006\nCUS*user1*Harry^Fletcher*SD\nORD*1*1*364*The 40-Year-Old Virgin*29.98\nORD*2*1*299*Pulp Fiction*29.99\nRun Code Online (Sandbox Code Playgroud)\n\n这就是我们转型的预期结果:
\n\n<Order>\n <header>\n <order-id>1</order-id>\n <status-code>0</status-code>\n <net-amount>59.97</net-amount>\n <total-amount>64.92</total-amount>\n <tax>4.95</tax>\n <date>Wed Nov 15 13:45:28 EST 2006</date>\n </header>\n <customer-details>\n <username>user1</username>\n <name>\n <firstname>Harry</firstname>\n <lastname>Fletcher</lastname>\n </name>\n <state>SD</state>\n </customer-details>\n <order-item>\n <position>1</position>\n <quantity>1</quantity>\n <product-id>364</product-id>\n <title>The 40-Year-Old Virgin</title>\n <price>29.98</price>\n </order-item>\n <order-item>\n <position>2</position>\n <quantity>1</quantity>\n <product-id>299</product-id>\n <title>Pulp Fiction</title>\n <price>29.99</price>\n </order-item>\n</Order>\nRun Code Online (Sandbox Code Playgroud)\n\nSmooks 配置
\n\n我们只需指定 SmooksEDIParser\xe2\x80\x89 作为流解析器。可以添加更多转换配置来进一步转换此消息。\n这里是配置(“smooks-config.xml”):
\n\n<?xml version="1.0"?>\n<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"\n xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.1.xsd">\n\n<!--\nConfigure the EDI Reader to process the message stream into a stream of SAX events.\n-->\n<edi:reader mappingModel="/example/edi-to-xml-order-mapping.xml" />\n\n</smooks-resource-list>\nRun Code Online (Sandbox Code Playgroud)\n\n这是 edi 映射(“/src/main/java/example/edi-to-xml-order-mapping.xml”):
\n\n<?xml version="1.0" encoding="UTF-8"?>\n<medi:edimap xmlns:medi="http://www.milyn.org/schema/edi-message-mapping-1.0.xsd">\n<medi:description name="DVD Order" version="1.0" />\n<medi:delimiters segment=" " field="*" component="^" sub-component="~" />\n<medi:segments xmltag="Order">\n <medi:segment segcode="HDR" xmltag="header">\n <medi:field xmltag="order-id" />\n <medi:field xmltag="status-code" />\n <medi:field xmltag="net-amount" />\n <medi:field xmltag="total-amount" />\n <medi:field xmltag="tax" />\n <medi:field xmltag="date" />\n </medi:segment>\n <medi:segment segcode="CUS" xmltag="customer-details">\n <medi:field xmltag="username" />\n <medi:field xmltag="name">\n <medi:component xmltag="firstname" />\n <medi:component xmltag="lastname" />\n </medi:field>\n <medi:field xmltag="state" />\n </medi:segment>\n <medi:segment segcode="ORD" xmltag="order-item" maxOccurs="-1">\n <medi:field xmltag="position" />\n <medi:field xmltag="quantity" />\n <medi:field xmltag="product-id" />\n <medi:field xmltag="title" />\n <medi:field xmltag="price" />\n </medi:segment>\n</medi:segments>\n</medi:edimap>\nRun Code Online (Sandbox Code Playgroud)\n\n执行转换:
\n\n// Instantiate Smooks with the config...\nSmooks smooks = new Smooks("smooks-config.xml");\n\ntry {\n// Filter the input message to the outputWriter...\nsmooks.filterSource(new StreamSource(messageIn), new\nStreamResult(messageOut));\n} finally {\nsmooks.close();\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1865 次 |
| 最近记录: |