|
|
|
ช่วยด้วย เกี่ยวกับ xml_parser ด่วนมาก งงมาก มีวิธีไหนที่เราจะแยกค่าออกจากข้อมูลที่เป็น binary ได้บ้างโดย |
|
|
|
|
|
|
|
อาจจะช้า เพราะอย่างด้วยรึป่าวฮะ network , client and server ถ้าไม่ก็ลองใช้ code นี้ดูนะฮะ
/////////////////////////////////////// get_xml_array.inc.php /////////////////////////////
<?php
function _get_xml_array($values, &$i)
{
$child = array();
if ($values[$i]['value']) array_push($child, $values[$i]['value']);
while (++$i < count($values))
{
switch ($values[$i]['type'])
{
case 'cdata':
array_push($child, $values[$i]['value']);
break;
case 'complete':
$name = $values[$i]['tag'];
$size = sizeof($child[$name]);
$child[$name][$size]['#'] = $values[$i]['value'];
if($values[$i]['attributes'])
{
$child[$name][$size]['@'] = $values[$i]['attributes'];
}
break;
case 'open':
$name = $values[$i]['tag'];
$size = sizeof($child[$name]);
if($values[$i]['attributes'])
{
$child[$name][$size]['@'] = $values[$i]['attributes'];
$child[$name][$size]['#'] = _get_xml_array($values, $i);
}
else
{
$child[$name][$size]['#'] = _get_xml_array($values, $i);
}
break;
case 'close':
return $child;
break;
}
}
return $child;
}
function get_xml_array($data)
{
$values = array();
$index = array();
$array = array();
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($parser, $data, $values, $index);
xml_parser_free($parser);
$i = 0;
$name = $values[$i]['tag'];
$array[$name]['@'] = $values[$i]['attributes'];
$array[$name]['#'] = _get_xml_array($values, $i);
return $array;
}
?>
/////////////////////////////////////// array.fun.php /////////////////////////////
อันนี้ใช้ดูค่าที่ได้จาก ข้างบนนะฮะ
<?
function print_a( $TheArray )
{ // Note: the function is recursive
echo "<table border=1>\n";
$Keys = array_keys( $TheArray );
foreach( $Keys as $OneKey )
{
echo "<tr>\n";
echo "<td bgcolor='#727450'>";
echo "<B>" . $OneKey . "</B>";
echo "</td>\n";
echo "<td bgcolor='#C4C2A6'>";
if ( is_array($TheArray[$OneKey]) )
print_a($TheArray[$OneKey]);
else
echo $TheArray[$OneKey];
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
?>
/////////////////////////////////// วิธีใช้ //////////////////////////////////////
<?
//include("../config/eng.php");
include("../function/function.php");
include ('classes/get_xml_array.inc.php');
//include("../config/p" . $getProvince . ".php");
//include("../config/thai_district.php");
$filename = Full_Path . "eppdd" . $getProvince . ".xml";
if (file_exists ($filename)) {
$data = implode("", file($filename));
$data = get_xml_array($data);
} else {echo "Error";}
print_a($data);
?>
ลองประยุกต์ดูฮะ อาจพอช่วยได้บ้างนะฮะ
|
|
|
|
|
Date :
9 มิ.ย. 2548 17:01:01 |
By :
mairu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|