OuSob Home Page Code XML Output
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Server SYSTEM "edi_to_xml.dtd">

<!-- EDI to XML with PHP from OuSob --> 

<root>
<isa>
  <isa_1>00</isa_1>
  <isa_2></isa_2>
  <isa_3>00</isa_3>
  <isa_4></isa_4>
  <isa_5>01</isa_5>
  <isa_6>159008395TEST</isa_6>
  <isa_7>ZZ</isa_7>
  <isa_8>00697986802TST</isa_8>
  <isa_9>060424</isa_9>
  <isa_10>1352</isa_10>
  <isa_11>U</isa_11>
  <isa_12>00401</isa_12>
  <isa_13>000000007</isa_13>
  <isa_14>0</isa_14>
  <isa_15>T</isa_15>
  <isa_16>&gt;</isa_16>
</isa>
<gs>
  <gs_1>MO</gs_1>
  <gs_2>159008395</gs_2>
  <gs_3>007924772</gs_3>
  <gs_4>20060424</gs_4>
  <gs_5>1352</gs_5>
  <gs_6>4</gs_6>
  <gs_7>X</gs_7>
  <gs_8>004010</gs_8>
</gs>
<st>
  <st_1>650</st_1>
  <st_2>0004</st_2>
</st>
<bgn>
  <bgn_1>13</bgn_1>
  <bgn_2>DNP2006031309452251776</bgn_2>
  <bgn_3>20060313</bgn_3>
  <bgn_4></bgn_4>
  <bgn_5></bgn_5>
  <bgn_6></bgn_6>
  <bgn_7>RD</bgn_7>
  <bgn_8>IT</bgn_8>
</bgn>
<n1>
  <n1_1>8R</n1_1>
  <n1_2>SCR34, AEP STREAM</n1_2>
</n1>
<n3>
  <n3_1>368 ROCKY RD</n3_1>
</n3>
<n4>
  <n4_1>DALLAS</n4_1>
  <n4_2>TX</n4_2>
  <n4_3>78368</n4_3>
</n4>
<per>
  <per_1>IC</per_1>
  <per_2>SCR34, AEP STREAM</per_2>
  <per_3>TE</per_3>
  <per_4>9999999999</per_4>
</per>
<n1>
  <n1_1>8S</n1_1>
  <n1_2>AEP</n1_2>
  <n1_3>1</n1_3>
  <n1_4>7924772</n1_4>
  <n1_5></n1_5>
  <n1_6>40</n1_6>
</n1>
<n1>
  <n1_1>SJ</n1_1>
  <n1_2>STREAM GAS &amp; ELECTRIC</n1_2>
  <n1_3>1</n1_3>
  <n1_4>159008395</n1_4>
  <n1_5></n1_5>
  <n1_6>41</n1_6>
</n1>
<hl>
  <hl_1>1</hl_1>
  <hl_2></hl_2>
  <hl_3>EV</hl_3>
  <hl_4>0</hl_4>
</hl>
<ref>
  <ref_1>8X</ref_1>
  <ref_2>RD002</ref_2>
</ref>
<ref>
  <ref_1>PH</ref_1>
  <ref_2>01</ref_2>
</ref>
<ref>
  <ref_1>Q5</ref_1>
  <ref_2></ref_2>
  <ref_3>10032789460343010</ref_3>
</ref>
<ref>
  <ref_1>SU</ref_1>
  <ref_2>N</ref_2>
</ref>
<dtm>
  <dtm_1>211</dtm_1>
  <dtm_2>20060316</dtm_2>
</dtm>
<se>
  <se_1>15</se_1>
  <se_2>0004</se_2>
</se>
<ge>
  <ge_1>1</ge_1>
  <ge_2>4</ge_2>
</ge>
<iea>
  <iea_1>1</iea_1>
  <iea_2>000000007</iea_2>
</iea>
<the_code>
<?php

$lt               = chr(60);
$gt               = chr(62);
$i                = 0;
$j                = 0;
$indent           = 0;

$file = "ampro.x12";

$fp   = @file_get_contents($file);

if( !$fp ){
  printf("\nCould not open file $file\n");
  exit;
}

$segments      = explode("~",$fp);
$segment_lenth = sizeof($segments);

printf("%s?xml version=\"1.0\" encoding=\"UTF-8\" ?%s\n",$lt,$gt);
printf("<!DOCTYPE Server SYSTEM \"edi_to_xml.dtd\">\n\n");
printf("<!-- EDI to XML with PHP from OuSob --> \n\n");
printf("<root>\n"); 

for($i=0; $i<$segment_lenth; $i++){
  $elements      = explode("*",$segments[$i]);
  $element_lenth = sizeof($elements);
  $record_type   = strtolower(trim($elements[0],"\r\n\t\0"));

  if( empty($record_type) ){
    break;
  }

  printf("%s<%s>\n",str_repeat(" ",$indent),$record_type); 

  for($j=1; $j<$element_lenth; $j++){
    printf("%s<%s_%s>%s</%s_%s>\n",str_repeat(" ",($indent+2)),$record_type,$j,htmlspecialchars(trim($elements[$j])),$record_type,$j); 
  }

  printf("%s</%s>\n",str_repeat(" ",$indent),$record_type); 
}


$x = file_get_contents("xxx.php");

printf("<the_code>%s</the_code>\n",$x); 

printf("</root>\n"); 

?>
</the_code>
</root>

OuSob Home Page Top  XML Output