16
SMOOKS를 사용하여 XML 파일을 EDI 파일로 변환하려면 어떻게해야합니까?SMOOKS를 사용하는 EDI 파일 생성
EDI를 XML로 변환 할 수 있는데, 실제로 이것은 SMOOKS에서 제공하는 예제의 일부입니다.
SMOOKS를 사용하여 XML 파일을 EDI 파일로 변환하려면 어떻게해야합니까?SMOOKS를 사용하는 EDI 파일 생성
EDI를 XML로 변환 할 수 있는데, 실제로 이것은 SMOOKS에서 제공하는 예제의 일부입니다.
귀하의 질문에 따라 나는 그것에 대한 연구를 해 보았습니다. 도움이되는지 확인하십시오.
그래서 여기에 변환되는 소스 EDI 파일입니다 :
HDR*1*0*59.97*64.92*4.95*Wed Nov 15 13:45:28 EST 2006
CUS*user1*Harry^Fletcher*SD
ORD*1*1*364*The 40-Year-Old Virgin*29.98
ORD*2*1*299*Pulp Fiction*29.99
그리고 이것은 우리의 변화의 예상 결과입니다
<Order>
<header>
<order-id>1</order-id>
<status-code>0</status-code>
<net-amount>59.97</net-amount>
<total-amount>64.92</total-amount>
<tax>4.95</tax>
<date>Wed Nov 15 13:45:28 EST 2006</date>
</header>
<customer-details>
<username>user1</username>
<name>
<firstname>Harry</firstname>
<lastname>Fletcher</lastname>
</name>
<state>SD</state>
</customer-details>
<order-item>
<position>1</position>
<quantity>1</quantity>
<product-id>364</product-id>
<title>The 40-Year-Old Virgin</title>
<price>29.98</price>
</order-item>
<order-item>
<position>2</position>
<quantity>1</quantity>
<product-id>299</product-id>
<title>Pulp Fiction</title>
<price>29.99</price>
</order-item>
</Order>
Smooks 구성
y SmooksEDIParser를 스트림 해석기로 지정하십시오. 이 메시지를 변환하기 위해 더 많은 변환 구성을 추가 할 수 있습니다. 여기
<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.1.xsd">
<!--
Configure the EDI Reader to process the message stream into a stream of SAX events.
-->
<edi:reader mappingModel="/example/edi-to-xml-order-mapping.xml" />
</smooks-resource-list>
는 "/src/main/java/example/edi-to-xml-order-mapping.xml"는 EDI 매핑 (의 : 다음은 구성 ("smooks-config.xml에")입니다) : 변환을 실행
<?xml version="1.0" encoding="UTF-8"?>
<medi:edimap xmlns:medi="http://www.milyn.org/schema/edi-message-mapping-1.0.xsd">
<medi:description name="DVD Order" version="1.0" />
<medi:delimiters segment=" " field="*" component="^" sub-component="~" />
<medi:segments xmltag="Order">
<medi:segment segcode="HDR" xmltag="header">
<medi:field xmltag="order-id" />
<medi:field xmltag="status-code" />
<medi:field xmltag="net-amount" />
<medi:field xmltag="total-amount" />
<medi:field xmltag="tax" />
<medi:field xmltag="date" />
</medi:segment>
<medi:segment segcode="CUS" xmltag="customer-details">
<medi:field xmltag="username" />
<medi:field xmltag="name">
<medi:component xmltag="firstname" />
<medi:component xmltag="lastname" />
</medi:field>
<medi:field xmltag="state" />
</medi:segment>
<medi:segment segcode="ORD" xmltag="order-item" maxOccurs="-1">
<medi:field xmltag="position" />
<medi:field xmltag="quantity" />
<medi:field xmltag="product-id" />
<medi:field xmltag="title" />
<medi:field xmltag="price" />
</medi:segment>
</medi:segments>
</medi:edimap>
:
// Instantiate Smooks with the config...
Smooks smooks = new Smooks("smooks-config.xml");
try {
// Filter the input message to the outputWriter...
smooks.filterSource(new StreamSource(messageIn), new
StreamResult(messageOut));
} finally {
smooks.close();
}
당신이 EDI 파일에서 XML 파일을 만듭니다 여기에 설명이 예. 그러나 XML 데이터에서 EDI 파일을 준비하라는 질문이 제기되었습니다. 어떻게 할 수 있는지 알려주십시오. – RCS