This project has moved and is read-only. For the latest updates, please go here.

Two Fixes - Both up for Discussion

Oct 11, 2013 at 1:27 AM
I've finally upgraded my project from an earlier alpha release and came across two issues in output compared with 1.0 release

1) loss of WhiteSpace preserving in ISA header
OLD: ISA*00*          *00*          *01*ABCCOM         *....
NEW: ISA*00**00**01*ABCCOM         *....
I have Modifed EdiHelper to add LoadOptions.PreserveWhitespace to serialization
        public static XElement Serialize<T>(T instance)
            var serializer = new XmlSerializer(typeof(T), typeof(T).Namespace);
            using (var ms = new MemoryStream())
                serializer.Serialize(ms, instance);
                ms.Position = 0;
                return XElement.Load(ms,LoadOptions.PreserveWhitespace);
2) Ability to have no SegmentTerminator
Although defaulted to "~" for X12, Because of the IsNullorEmpty() you cannot simply set it to "" and Null gives you the default of "~"

I have Changed InterchangeContextHelper to use == String.Empty
        public static InterchangeContext MergeInterchangeContext(XElement element, InterchangeContext interchangeContext)
            if (element == null) throw new ArgumentNullException("element");
            var result = GetInterchangeContext(element.Name.NamespaceName);
            if (interchangeContext == null) return result;

            if (interchangeContext.ComponentDataElementSeparator == String.Empty) result.ComponentDataElementSeparator = interchangeContext.ComponentDataElementSeparator;
            if (interchangeContext.DataElementSeparator == String.Empty) result.DataElementSeparator = interchangeContext.DataElementSeparator;
            if (interchangeContext.ReleaseIndicator == String.Empty) result.ReleaseIndicator = interchangeContext.ReleaseIndicator;
            if (interchangeContext.RepetitionSeparator == String.Empty) result.RepetitionSeparator = interchangeContext.RepetitionSeparator;
            if (interchangeContext.SegmentTerminator == String.Empty) result.SegmentTerminator = interchangeContext.SegmentTerminator;

            return result;
Not sure is this is necessary, but the example EDI outtput I was provided that I'm trying to mirror doesn't have ~'s
Oct 14, 2013 at 11:55 AM
Hi mate,

Regarding 1. - it does preserve the white spaces, when they are part of the values for each node. It does not preserve the white spaces between the nodes though, as they are insignificant and can potentially increase the size. Could you give an example on why do you need the xml formatted ?

Regarding 2. - Yes you can pass in a blank SegmentSeparator, when converting from raw edi to xml. This will assign a new line value for SegmentSeparator.
The other way around, converting from xml\c# to raw edi, does not allow a blank segment separator, because this is invalid X12 format. You can leave it blank only if you designate a suffix according to X12 documentation. The syffix can be any of the CR (carriage return), LF (line feed), or CR LF.

What you can do in that case is to set SegmentSeparator to Environment.NewLine and it won't append the default '~' at the end. Then the output is a list of strings, where every string is an edi segment and you can build the final raw edi message anyway you want.

Let me know if that helped,
Oct 14, 2013 at 5:16 PM
I'm not converting to XML, I am starting with an cs class build from xsd2code and populating the xsd manually to build the EDI interchange. I don't need to write the XML, although I realize internally thats what's being built. The code I’m using is the same example project I gave you last year, only upgraded for your 1.0 release and now based upon a 214 transaction.

As an initial test, I am trying to mirror a file that was given to me as an example x12 transaction. This interchange has two areas of blank spaces in the header between the ** and note the entire message has no ~ at the end of all the lines? See below
ISA*00*          *00*          *ZZ*STDSP5AC       *ZZ*GTNEXUS        *080326*1032*U*00401*000000263*0*T*>
L11*Unidentified Airlines*SCA
N1*SH*Shipper Name*94*CNZHSPC-TMPF
N3*Chengxin Middle Road*Xinqian Town, Huangyan District
N1*OT*Shanghai International Airport*94*SHA
N1*DT*DFW International Airport*94*DFW
N1*CN*Consignee Name*94*STDCN
N3*2560 W. Commerce Street
K1*comments go here
Appreciate the help

Mike Pisano
Feb 25, 2014 at 10:58 PM
I ran into the whitespace problem as well.

If there was any content besides the a whitespace character, then the entire string functioned as expected... only when there was a completely blank string such as in S_GS.D_142_2 with S_GS.D_479_1 == "00" (no security) did it trim the string.
Mar 11, 2014 at 5:44 PM
I solved this problem by using the 0160 ASCII Code for WhiteSpace Generation. ( ALT + 0160 ). The library does not trim de string when using this character.

Hope this helps.
Apr 30, 2014 at 9:08 AM
This has now been included in Release 2.0