xlate / staedi

StAEDI - Streaming API for EDI: Java library featuring a reader/parser, writer/generator, and validation
Apache License 2.0
123 stars 35 forks source link

How to define element inside element in schema? #443

Closed uraajan closed 3 months ago

uraajan commented 5 months ago

Describe the bug In an inbound transaction, an element has 2 parts, and the ANSI schema contains elements part-1 and part-2 inside the element definition.

How to define this use case in STAEDI schema? **To Reproduce** Steps to reproduce the behavior. **Expected behavior** A clear and concise description of what you expected to happen. **Additional context** Add any other context about the problem here.
MikeEdgar commented 5 months ago

Hi @uraajan , what you're looking for is a composite element. The composite can be referenced from a segmentType just like an element.

<elementType name="E0143" number="143" base="string" minLength="3" maxLength="3"/>
<elementType name="E0329" number="329" base="string" minLength="4" maxLength="9" />

<compositeType name="C900">
  <sequence>
    <element type="E0143" minOccurs="1" />
    <element type="E0329" />
  </sequence>
<compositeType>

<segmentType name="FOO">
  <sequence>
    <element type="E0143" minOccurs="1" />
    <composite type="C900" />
  </sequence>
<segmentType>
uraajan commented 5 months ago

Hello @MikeEdgar Thanks for taking up the question.

For a composite element, I assume a separator is mandatory, isn't it? In this case, there is no separator in the data. The data is CTN25 and in this, the first 3 characters CTN belong to Part-103.1 and this part has its own set of enumerations and the last 2 characters 25 belong to Part-103.2 and this part also has a different set of enumerations. Will composite element work in this case?

MikeEdgar commented 5 months ago

@uraajan Yes, you are right. Composites do require separators. I think what you're describing is simply a formatted element. You should use a simple element (CTN25) and then split the single value according to your trading partner agreement.

uraajan commented 5 months ago

I got it @MikeEdgar , but the problem here is CTN is just one of the enumeration values and there are hundreds of other enums in part 1, and in the same way 25 is just one of the enumeration values and there are hundreds of other enums in part 2 also. CTN25 is just one combination, and there could be thousands of combinations like this. Now to define it in STAEDI schema, we need to define enums separately for both parts, and what we need is like elements inside element. Is it possible to define this use case in STAEDI schema?

MikeEdgar commented 5 months ago

@uraajan I see your problem, but there isn't any way to describe something like that with the EDI schema. It's a common attribute to most schemas of other types as well - e.g. XSD or JSON Schema. There isn't a way to specify an enumeration for substrings of a field.

I think you could accomplish something like it in your application by declaring two lists/sets of allowed values and comparing positions 1-3 to the first set, and positions 4-5 to the other set

uraajan commented 5 months ago

Sure @MikeEdgar will try the workaround, thank you!

MikeEdgar commented 5 months ago

@uraajan at your convenience please let me know if the solution is okay and whether this can be closed for now.

Thank you!