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

Looping of Header, Detail and Summary

Dec 22, 2016 at 11:26 PM
Edited Dec 22, 2016 at 11:33 PM
EDI message is divided into Header (table 1), Detail (table 2) and Summary (table 3). When I parsed my 810 to XML then converted to JSON (via Newtonsoft.Json), I have the following problem:

All the xmls with tag <Loop....> are combined into the same list or group. All of my detail segments are combined with header segments.

Here is the sample of the Json:
            "Loop": [{
                    "@LoopId": "N1",
                    "@Name": "Party",
                    "N1": {
                        "#comment": [],
                        "N101": "BT",
                        "N102": "ACME DISTRIBUTING COMPANY"
                    },
                    "N3": { /*Address Information*/ "N301": "P.O. BOX 33327"
                    },
                    "N4": {
                        "#comment": [],
                        "N401": "ANYTOWN",
                        "N402": "NJ",
                        "N403": "44509"
                    }
                }, {
                    "@LoopId": "N1",
                    "@Name": "Party",
                    "N1": {
                        "#comment": [],
                        "N101": "ST",
                        "N102": "THE CORNER STORE"
                    },
                    "N3": { /*Address Information*/ "N301": "601 FIRST STREET"
                    },
                    "N4": {
                        "#comment": [],
                        "N401": "CROSSROADS",
                        "N402": "MI",
                        "N403": "48106"
                    }
                }, {
                    "@LoopId": "N1",
                    "@Name": "Party",
                    "N1": {
                        "#comment": [],
                        "N101": "VN",
                        "N102": "SMITH CORPORATION"
                    },
                    "N3": { /*Address Information*/ "N301": "900 EASY STREET"
                    },
                    "N4": {
                        "#comment": [],
                        "N401": "BIG CITY",
                        "N402": "NJ",
                        "N403": "15455"
                    }
                }, {
                    "@LoopId": "IT1",
                    "@Name": "ITEM",
                    "IT1": {
                        "IT101": null,
                        "#comment": [],
                        "IT102": "3",
                        "IT103": {
                            "#text": "CA" /*Case*/
                        },
                        "IT104": "12.75",
                        "IT105": null,
                        "IT106": "VC",
                        "IT107": "6900"
                    },
                    "CTP": {
                        "#comment": [],
                        "CTP01": "RS",
                        "CTP02": "FCP",
                        "CTP03": "12.5"
                    },
                    "Loop": [{
                            "@LoopId": "PID",
                            "@Name": "PRODUCT/ITEM",
                            "PID": {
                                "PID01": "F",
                                "PID02": "08",
                                "PID03": null,
                                "PID04": null,
                                "PID05": "ITEM DESCRIPTION 1/10 LB"
                            }
                        }, {
                            "@LoopId": "PID",
                            "@Name": "PRODUCT/ITEM",
                            "PID": {
                                "PID01": "F",
                                "PID02": "08",
                                "PID03": null,
                                "PID04": null,
                                "PID05": "ITEM DESCRIPTION SECOND LINE"
                            }
                        }, {
                            "@LoopId": "SAC",
                            "@Name": "Service, Promotion, Allowance, or Charge Information",
                            "SAC": {
                                "#comment": [],
                                "SAC01": "A",
                                "SAC02": "B280",
                                "SAC03": null,
                                "SAC04": null,
                                "SAC05": "20.00",
                                "SAC06": null,
                                "SAC07": null,
                                "SAC08": "2.00",
                                "SAC09": null,
                                "SAC10": null,
                                "SAC11": null,
                                "SAC12": "02"
                            }
                        }
                    ]
                }, {
                    "@LoopId": "IT1",
                    "@Name": "ITEM",
                    "IT1": {
                        "IT101": null,
                        "#comment": [],
                        "IT102": "3",
                        "IT103": {
                            "#text": "CA" /*Case*/
                        },
                        "IT104": "12.75",
                        "IT105": null,
                        "IT106": "VC",
                        "IT107": "6900"
                    },
                    "CTP": {
                        "#comment": [],
                        "CTP01": "RS",
                        "CTP02": "FCP",
                        "CTP03": "15.5"
                    },
                    "Loop": [{
                            "@LoopId": "PID",
                            "@Name": "PRODUCT/ITEM",
                            "PID": {
                                "PID01": "F",
                                "PID02": "08",
                                "PID03": null,
                                "PID04": null,
                                "PID05": "ITEM DESCRIPTION 2"
                            }
                        }, {
                            "@LoopId": "PID",
                            "@Name": "PRODUCT/ITEM",
                            "PID": {
                                "PID01": "F",
                                "PID02": "08",
                                "PID03": null,
                                "PID04": null,
                                "PID05": "ITEM DESCRIPTION SECOND LINE"
                            }
                        }, {
                            "@LoopId": "SAC",
                            "@Name": "Service, Promotion, Allowance, or Charge Information",
                            "SAC": {
                                "#comment": [],
                                "SAC01": "A",
                                "SAC02": "B280",
                                "SAC03": null,
                                "SAC04": null,
                                "SAC05": "20.00",
                                "SAC06": null,
                                "SAC07": null,
                                "SAC08": "2.00",
                                "SAC09": null,
                                "SAC10": null,
                                "SAC11": null,
                                "SAC12": "02"
                            }
                        }
                    ]
                }
            ],
This is my sample EDI:

ISA*00* *00* *08*9251750000 *08*1234567890 *030627*1304*U*00401*000001403*0*P*>~
GS*PO*8019721193*1234567890*20030627*1304*1403*X*004010~
ST*810*0001~
BIG*040713*1001*040625*P89320~
NTE*GEN*59590001~
NTE*GEN*IF ANY CHANGES OR SHORTAGES PLEASE~
NTE*GEN*CONTACT TONY BRAYN (310) 526-1348~
NTE*GEN*OR EMAIL tony@gmail.COM~ REF\*AN\*547794~ PER\*BD\*JOHN JONES*TE*5552225555~
N1*BT*ACME DISTRIBUTING COMPANY~
N3*P.O. BOX 33327~
N4*ANYTOWN*NJ*44509~
N1*ST*THE CORNER STORE~
N3*601 FIRST STREET~
N4*CROSSROADS*MI*48106~
N1*VN*SMITH CORPORATION~
N3*900 EASY STREET~
N4*BIG CITY*NJ*15455~
ITD*01*3*2**10~
DTM*002*20030705~
DTM*118*20030704~
FOB*PB~
IT1**3*CA*12.75**VC*6900~
CTP*RS*FCP*12.5~
PID*F*08***ITEM DESCRIPTION 1/10 LB~
PID*F*08***ITEM DESCRIPTION SECOND LINE~
SAC*A*B280***20.00***2.00****02~
IT1**3*CA*12.75**VC*6900~
CTP*RS*FCP*15.5~
PID*F*08***ITEM DESCRIPTION 2~
PID*F*08***ITEM DESCRIPTION SECOND LINE~
SAC*A*B280***20.00***2.00****02~
TDS*5111*~
CAD*M****CONSOLIDATED TRUCK~
CTT*1*20~
SE*1*0001~
GE*1*1304~
IEA*1*000001403~


I'd like to have the capability to separate header, detail and summary into its own loop. Please give me some suggestions how to do it. I'd also like to group the segments that are related into a list. For example the following EDI message contains two line items:

IT1**3*CA*12.75**VC*6900~
CTP*RS*FCP*12.5~
PID*F*08***ITEM DESCRIPTION 1/10 LB~
PID*F*08***ITEM DESCRIPTION SECOND LINE~
SAC*A*B280***20.00***2.00****02~
IT1**3*CA*12.75**VC*6900~
CTP*RS*FCP*15.5~
PID*F*08***ITEM DESCRIPTION 2~
PID*F*08***ITEM DESCRIPTION SECOND LINE~
SAC*A*B280***20.00***2.00****02~


I want to be able to parse it to XML with a main loop that contains 2 line items and their related segments.

Thanks