Index
Accessing loaded EDI Data
Developers can access all data from EDI data loaded with the EDIFileLoader using the EDILightWeightDocument returned after calling the Load() method. Because EDIFileLoader does not use any rules file, there is no validation on the EDI data. More importantly there is no proper hierarchy data conforming to the EDI implementation guides as you would find in the EDIValidator component. There is only one main loop containing all the parsed segments and elements that exist in the EDI data. This gives developers the flexibility to group and use this data however they choose.
Example
const edi = require(‘rdpcrystal-edi-library‘);
let dataToLoad = “ISA*00* *00* *ZZ*133052274 …”;
//Create a new EDIFileLoader
let fileLoader = new edi.EDIFileLoader();
fileLoader.EDIDataString = dataToLoad;
//Returns an EDILightWeigthDocument
let doc = fileLoader.load();
From here we can just access EDI data from the EDILightWeightDocument
//Write out a visual representation of the loaded EDI document
writeDocumentTree(doc.Loops.getItem(0), 0);
function writeDocumentTree(loop, indent) {
if (loop != null) {
for (let i = 0; i < indent; i++) {
process.stdout.write(” “);
}
console.log(loop.Name);
indent++;
writeSegment(loop.Segments, indent);
if (loop.Loops != null) {
for (let i = 0; i < loop.Loops.Count; i++) {
writeDocumentTree(loop.Loops.getItem(i), indent);
}
indent++;
}
}
}
function writeSegment(segments, indent) {
for (let i = 0; i < segments.Count; i++) {
let seg = segments.getItem(i);
for (let i = 0; i < indent; i++) {
process.stdout.write(” “);
}
console.log(seg.Name);
writeElement(seg.Elements, indent);
}
}
function writeElement(elements, indent) {
for (let i = 0; i < elements.Count; i++) {
let elem = elements.getItem(i);
for (let i = 0; i < indent; i++) {
process.stdout.write(” “);
}
if (elem.Composite) {
console.log(“Composite”);
//Check for composite elements
if (elem.Elements != null && elem.Elements.Count > 0) {
writeElement(elem.Elements, ++indent);
indent–;
}
} else {
console.log(“[” + elem.DataValue + “]”);
}
}
}