How to parse XML file into PHP?

aohokqoy

New Member
I have used following xml file and tried to parse into php, but failed to parse. Have you any solution for parsing that code.\[code\]<?xml version="1.0" encoding="windows-1252" standalone="yes"?><?xml-stylesheet type="text/xsl" href="http://stackoverflow.com/questions/12739239/MovInven.xsl"?><!-- Generated by SMExport 4.77--> <RECORDS> <RECORD> <ROW CODIGO="1130003205" SUBCODIGO="1" FECHA="20120730" ALMACEN="1" NOMBRE_ARTICULO="00007 14-000" NOMBRE_ALMACEN="G ROMERO 1." NIT_ALMACEN="800134363-1" SALDO_INICIAL="-1" COSTO_UNITARIO="0" COSTO_TOTAL="0" ENTRADAS="0" SALIDAS="4" NUEVO_SALDO="-5" /> </RECORD></RECORDS>\[/code\]I am using following code to parse. But did not got any output from the following code.\[code\]<?php $file = "test.xml"; function contents($parser, $data){ echo $data; } function startTag($parser, $data){ echo "<b>"; } function endTag($parser, $data){ echo "</b><br />"; } $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startTag", "endTag"); xml_set_character_data_handler($xml_parser, "contents"); $fp = fopen($file, "r"); $data = http://stackoverflow.com/questions/12739239/fread($fp, 80000); if(!(xml_parse($xml_parser, $data, feof($fp)))){ die("Error on line " . xml_get_current_line_number($xml_parser)); } xml_parser_free($xml_parser); fclose($fp); ?>\[/code\]
 
Back
Top