--- /dev/null
+--- a/lib/edi4r.rb 2012-07-17 17:57:27.000000000 -0400
++++ b/lib/edi4r.rb 2012-07-17 17:51:48.000000000 -0400
+@@ -758,6 +758,7 @@
+ loop do
+ index += 1
+ seg = msg[index]
++ break if seg.nil?
+ next if child_mode and seg.level > level+1 # other descendants
+ break if seg.level <= level
+ results << seg
--- /dev/null
+#!/usr/bin/perl
+
+use XML::Edifact;
+use XML::LibXML;
+
+XML::Edifact::open_dbm();
+XML::Edifact::read_edi_message($ARGV[0]);
+my $xmlstr = &XML::Edifact::make_xml_message();
+XML::Edifact::close_dbm();
+
+my $dom = load_xml XML::LibXML(string => $xmlstr);
+
+print $dom->toString(),"\n";
+0;
+
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Data::Dumper;
+use vars qw/$debug/;
+
+use OpenILS::Utils::Cronscript;
+use OpenILS::Utils::Fieldmapper;
+use OpenILS::Application::AppUtils;
+use OpenILS::Application::Acq::EDI;
+use OpenSRF::Utils::Logger q/$logger/;
+
+INIT {
+ $debug = 1;
+}
+
+my %defaults = (
+ 'quiet' => 0,
+ 'test' => 0,
+);
+
+print "loading OpenILS environment... " if $debug;
+
+my $cs = OpenILS::Utils::Cronscript->new(\%defaults);
+
+my $opts = $cs->MyGetOptions;
+my $e = $cs->editor or die "Failed to get new CStoreEditor";
+
+print "creating acq.edi_message object from stdin\n" if $debug;
+my $message = new Fieldmapper::acq::edi_message;
+$message->message_type("ORDERS");
+
+my $input_field = $ENV{INPUT_IS_EDI} ? 'edi' : 'jedi';
+my $output_field = $ENV{INPUT_IS_EDI} ? 'jedi' : 'edi';
+{
+ local $/;
+ undef $/;
+ $message->$input_field(<STDIN>);
+
+}
+
+print "calling out to edi translator... \n" if $debug;
+
+my $r = attempt_translation OpenILS::Application::Acq::EDI($message, !$ENV{INPUT_IS_EDI});
+
+if (!$r) {
+ print STDERR "attempt_translation failed; see opensrf ERR logs\n";
+} else {
+ print $r->$output_field,"\n";
+}
+
+print "done.\n" if $debug;
+