java-to-xml short xml tags

81 views
Skip to first unread message

Serhii Pasko

unread,
May 26, 2021, 4:59:23 PM5/26/21
to Smooks Users
Hi everyone!
I am new in smooks, possible my questions are stupid
1. In example java-to-xml we see result like <org.smooks.examples.java2xml.model.Order><header><customerNu....
Is it possible to configure like  <Order><header><customerNu.... ???

2. Why I asking. I have task convert edi->java->edi.  The first step edi-java is preparation for converting edi to anything from java. In java I want to add additional logic if need. And issue that I had: org.apache.daffodil.japi.DaffodilUnparseErrorSAXException: Unparse Error: Expected element start event for {}Order, but received element start event for (invalid) {}com.smc.poc.edi.smooks.Order.
Models are from examples.

Maybe my approach not correct? I didn't find an example with two or more transformations together =(.
csv, edi, edifact, yaml... ->java + additional logic if need ->  csv, edi, edifact, yaml...

3. Not sure how will implement additional logic to java, thinking use java-to-java example, how to add additional steps still don't know...

Thanks! Big respect from Ukraine to the team!!! You doing amazing work!



Message has been deleted
Message has been deleted

Jeff Bradley

unread,
May 26, 2021, 5:37:52 PM5/26/21
to Smooks Users
Hello! I also am new so my answer may be lacking :) Claude is the expert around here.

Yes it can do what you need if I understand your question. Here is an example of output from mapping from EDI to Java and outputting the XML. 

<shipment-status-message>
<interchange>
<authorization-qualifier>00</authorization-qualifier>
<authorization-information></authorization-information>
<security-qualifier>00</security-qualifier>
<security-information></security-information>
<sender-qualifier>02</sender-qualifier>
<sender-id>ODFL </sender-id>
<receiver-qualifier>ZZ</receiver-qualifier>
<receiver-id>1234567 </receiver-id>
<date>170202</date>
<time>1244</time>
<repetition-separator>U</repetition-separator>
<version>00401</version>
<control-number>000001062</control-number>
<acknowledgment-requested>0</acknowledgment-requested>
<usage-indicator>P</usage-indicator>
<composite-separator>&gt;</composite-separator>
</interchange>
<group>
<group-code>QM</group-code>
<sender-id>ODFL</sender-id>
<receiver-id>1234567</receiver-id>
<date>20170202</date>
<time>124452</time>
<control-number>906</control-number>
<agency-code>X</agency-code>
<version>004010</version>
</group>
<transaction-sets>
<shipment-status>
<identifier-code>214</identifier-code>
<sequence>0001</sequence>
<reference-identification>02625962200</reference-identification>
<shipment-identification-number>NAMCLF0005633</shipment-identification-number>
<scac>TEST</scac>
<reference-numbers>
<reference-number>
<reference-identification>4550465693</reference-identification>
<reference-qualifier>PO</reference-qualifier>
</reference-number>
</reference-numbers>
<location-information/>
<assigned-number>1</assigned-number>
<indicator-code>D1</indicator-code>
<reason-code-1>NS</reason-code-1>
<status-code></status-code>
<reason-code-2></reason-code-2>
<date>20170202</date>
<time>1217</time>
<time-code>ET</time-code>
<weight-qualifier>G</weight-qualifier>
<weight-unit-code>L</weight-unit-code>
<weight>8142</weight>
<lading-quantity>15</lading-quantity>
<number-of-segments>7</number-of-segments>
<control-number>0001</control-number>
</shipment-status>
<shipment-status>
<identifier-code>214</identifier-code>
<sequence>0002</sequence>
<reference-identification>02625962201</reference-identification>
<shipment-identification-number>NAMCLF0005633</shipment-identification-number>
<scac>FOOB</scac>
<reference-numbers>
<reference-number>
<reference-identification>4550465694</reference-identification>
<reference-qualifier>PO</reference-qualifier>
</reference-number>
</reference-numbers>
<location-information/>
<assigned-number>1</assigned-number>
<indicator-code>D1</indicator-code>
<reason-code-1>NS</reason-code-1>
<status-code></status-code>
<reason-code-2></reason-code-2>
<date>20170202</date>
<time>1217</time>
<time-code>ET</time-code>
<weight-qualifier>G</weight-qualifier>
<weight-unit-code>L</weight-unit-code>
<weight>8142</weight>
<lading-quantity>15</lading-quantity>
<number-of-segments>7</number-of-segments>
<control-number>0001</control-number>
</shipment-status>
</transaction-sets>
<ge>
<transaction-count>2</transaction-count>
<control-number>9185</control-number>
</ge>
<iea>
<group-count>1</group-count>
<control-number>000015198</control-number>
</iea>
</shipment-status-message>

That can be sent to a Java to Java Smooks filter along with configuration like the one below that creates a map of objects.

<?xml version="1.0" encoding="UTF-8" ?>
<smooks-resource-list
xmlns:json="https://www.smooks.org/xsd/smooks/json-1.3.xsd"
xmlns:jb="https://www.smooks.org/xsd/smooks/javabean-1.6.xsd"
xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd">

<jb:bean beanId="interchange" class="java.util.HashMap" createOnElement="interchange">
<jb:value data="#/receiverId" property="myReceiver" />
<jb:value data="#/senderId" property="mySender" />
<jb:value data="time" property="time" />
<jb:value data="receiverQualifier" property="qualifier" />
</jb:bean>

<jb:bean beanId="group" class="java.util.HashMap" createOnElement="group" retain="true">
<jb:value data="groupCode" property="groupCode" />
<jb:value data="#/time" property="time" />
</jb:bean>

<jb:bean beanId="shipmentStatuses" class="java.util.ArrayList" createOnElement="shipmentStatuses" retain="true">
<jb:wiring beanIdRef="shipmentStatus" />
</jb:bean>

<jb:bean beanId="shipmentStatus" class="java.util.HashMap" createOnElement="shipmentStatuse">
<jb:value data="sequence" property="sequence" />
<jb:value data="shipmentIdentificationNumber" property="shipmentId"/>
</jb:bean>

</smooks-resource-list>

You can specify which beans to retain in the context and retrieve them. The JSON representation of the shipmentStatuses bean after the above transforms is:

[{"sequence":"0001","shipmentId":"NAMCLF0005633"},{"sequence":"0001","shipmentId":"NAMCLF0005633"}]

Sorry, had to fix this a couple times. Had some JSON stuff in there needed to remove :)

Claude Mamo

unread,
May 27, 2021, 6:21:29 AM5/27/21
to smook...@googlegroups.com
Welcome to the forum Serhii!

1. In example java-to-xml we see result like <org.smooks.examples.java2xml.model.Order><header><customerNu....
Is it possible to configure like  <Order><header><customerNu.... ???

The above problem may be solved in XStream. A solution was posted for this problem though you might need to extend org.smooks.engine.resource.reader.XStreamXMLReader. You could also solve this problem in Smooks with pipelines but I think the XStream solution is more efficient.

Maybe my approach not correct? I didn't find an example with two or more transformations together =(.
csv, edi, edifact, yaml... ->java + additional logic if need ->  csv, edi, edifact, yaml...

I can't comment on whether your approach is correct for your particular use case. EDI-to-SAX-to-POJOs transformations can be fairly expensive in terms of time so you might want to benchmark your solution early on if you have large (GBs) documents to process. About the examples, we have to add more although this might provide a good starting point: https://github.com/smooks/smooks-examples/blob/v1.0.2/pipelines/smooks-config.xml. A blog post describes in detail the example.

3. Not sure how will implement additional logic to java, thinking use java-to-java example, how to add additional steps still don't know...

Would have to know more about your use case but you could implement your own visitors and integrate with other Java libraries. Be sure to check out the docs for Smooks 2. They are WIP but you can get a clear understanding of Smook's processing model.

Claude


--
You received this message because you are subscribed to the Google Groups "Smooks Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smooks-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/smooks-user/dfb61554-47af-4dee-a53f-bba56aee19e3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages