A way to easily format a document to match it's schema?

Here’s my scenario.

We are currently running IS 6.5. I am attempting to replace a portion (the guts) of an existing interface.

The client program resides on one of our mainframe regions which invokes the existing WebMethods service. Unfortunately, I am only able to make the change provided I do not change the client.

The mainframe client passes in all the data to my service padded to the max length of the data in DB2 source tables. There are 100 or so fields.

In my service, I mapped the inbound document type the input document of the destination webservice I imported.

What I am running in to is the webservice throw soap exceptions because the data length do not match the maximum of the target system.

So…here is my question…

Is there anyway to easily format the data to the schema contraints without putting in 100 “truncate” transformer steps for each data element? (a very tedious process considering I have 6 other interface to update with different document types)

If I run pub.schema.validate against the document I pretty much error out on every single item because they are longer than max of the target.

I think WmSamples has an example of traversing an IS document (via the IData interface) to visit each node. With that you should be able to create a service that does a trim of each node that is of class String.

That’s what I pretty much figured.

Also, I can’t actually do a trim, it’s actually that I need to truncate to the max length.

The only problem is I still need to get the max length constraint on the document type elements.

Do you by any chance know how you can do that?

Very interesting challenge.
I guess you can use xsom to parse the schema, but doing it inside IS is too heavy.
you may want to create some code using xsom, extract all the maxLength settings and create a list of:
in IS, you can cache it with hashmap, then when you traversing the document (as Rob suggested), truncate the string with its corresponding maxLength value.
I hope there is bettere way to do this.

Just some thoughts.

D’oh! My bad for translating trunc to trim. That is indeed quite a different task.

I guess I was thinking trim because the padding added generally far exceeds the need. Thus trimming the excess spaces may be sufficient for the majority of the fields. Then you could trunc only the fields that really need it, not all 100+ of them.

How are you getting the data from the mainframe? I ask because depending on that, you might be able to leverage the flat-file schema features that can trim and/or use a custom formatting service to truncate to length. Let me know if that sounds feasible and we can dig into details.

I think there is a method to get the Field size property of a FF schema that is handy if you want to make sure the string isn’t longer than a certain length.

Have a look in the WmFlatFile package