ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î


php ³»ÀåÇÔ¼öÀ» ÀÌ¿ëÇÑ XML Parser
12³â Àü
php.net XML Parser ¿¡ º¸½Ã¸é ÀÚ¼¼ÇÑ ¼³¸íÀ» º¸½Ç ¼ö ÀÖ½À´Ï´Ù.
º¸Åë 4.3 ¹öÀü ÀÌ»óÀÌ¸é ¹«¸®¾øÀÌ µ¹¾Æ°¡´Â°Í °°³×¿ä

<?
/**
*XML Parser À» ÀÌ¿ëÇÏ¿© XMLÀ» ´Ù·é´Ù.
*
* ÀÚ¼¼ÇÑ ¼³¸í¹× ·¹ÆÛ·±½º´Â http://kr.php.net/manual/kr/book.xml.php ¸¦ Âü°í
*/

$rXml = xml_parser_create(); // xml Æļ­¸¦ »ý¼º½ÃŲ´Ù.
$arXml = array(); // Àӽà ¹è¿­
$strXml = ''; // xmlÀÇ ³»¿ëÀ» ÀúÀåÇÒ º¯¼ö
/**
* file_get_contents µîÀÇ ÆÄÀÏ ³»¿ëÀ» Àд ¿©·¯ ÇÔ¼ö¸¦ ÀÌ¿ëÇÒ ¼ö ÀÖ´Ù.
*/
$fp = fopen('./test.xml', 'r'); // xml ÆÄÀÏÀ» Àд´Ù.
if($fp) // Á¤»óÀûÀ¸·Î ÆÄÀÏÀÌ ¿­·È´Ù¸é
{
while (!feof($fp)) { // EOF°¡ µÉ¶§±îÁö
$strXml .= fread($fp, 1024); // 1024 ¹ÙÀÌÆ®¾¿ Àо Àӽà º¯¼ö¿¡ ³Ö´Â´Ù.
}
fclose($fp); // ÆÄÀÏÀ» ´Ý´Â´Ù.
}
xml_parser_set_option($rXml, XML_OPTION_CASE_FOLDING, 0); // ´ë¹®ÀÚ·Î º¯°æ (±âº»ÀÌ enableÀ̶ó disableÇÔ)
xml_parser_set_option($rXml, XML_OPTION_SKIP_WHITE, 1); // °ø¹é°ªÀ» ¹«½ÃÈù´Ù.
xml_parse_into_struct($rXml, $strXml, $arXml); // ÀоîµéÀÎ XMLÀ» ÀÌ¿ëÇؼ­ ¹è¿­¿¡ XML±¸Á¶¸¦ ´ã´Â´Ù.
xml_parser_free($rXml);

$strNodeKey = null;
$arXmlAssoc = array();
// ¿¬°ü¹è¿­ Çü½ÄÀ¸·Î Çϱâ À§Çؼ­ ¾Æ·¡¿Í °°ÀÌ Ã³¸®
foreach ($arXml as $key => $arNode)
{
switch ($arNode['type'])
{
case 'open':
$strNodeKey = $arNode['tag'];
$arXmlAssoc[$arNode['tag']];
break;

case 'complete':
if(is_array($arNode['attributes']))
{
$arXmlAssoc[$strNodeKey][$arNode['tag']][] = array('attr' => $arNode['attributes'], 'value' => $arNode['value']);
}
else
{
$arXmlAssoc[$strNodeKey][$arNode['tag']][] = $arNode['value'];
}
break;

case 'close':
$nOpenNodeKey = null;
break;
}
}




// Echo
foreach ($arXmlAssoc['Province']['Area'] as $arElement)
{
echo $arElement['attr']['code'];
echo '=>';
echo $arElement['value'];
echo '<BR>';
}
?>


http://kr.php.net/manual/kr/book.xml.php
ÃßõÃßõ : 609 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
2,884
PHP¿¡¼­ MP3 ÆÄÀÏÀ» Á÷Á¢ ÀÐ°í ½ºÆ®¸®¹Ö Çϱâ
2,883
ÇöÀç ÆäÀÌÁö°¡ location.reload()¿¡ ÀÇÇØ »õ·Î°íħµÇ¾ú´ÂÁö
2,882
ÅؽºÆ® ÆÄÀÏÀ» Àаí, °¢ ÁÙÀÇ ³¡¿¡¼­ 6±ÛÀÚ¸¦ »èÁ¦ÇÑ ÈÄ, °á°ú¸¦ »õ·Î¿î ÆÄÀÏ¿¡ ÀúÀåÇÕ´Ï´Ù.
2,881
cURLÀ» »ç¿ëÇÏ¿© ¸®´ÙÀÌ·ºÆ®¸¦ µû¶ó°¡ ÃÖÁ¾ URL °¡Á®¿À±â
2,880
[PHP] $_SERVER ȯ°æº¯¼ö
2,879
10Áø¼ö <-> 16Áø¼ö º¯È¯±â PHP¼Ò½º
2,878
ÅؽºÆ®¿¡ Á÷Á¢ ±×¶óµ¥ÀÌ¼Ç »ö»óÀ» Àû¿ëÇÏ·Á¸é?
2,877
CSS¸¦ »ç¿ëÇÏ¿© ¿ä¼ÒÀÇ ³»¿ë¹°¿¡ µû¶ó width¸¦ Á¶Á¤ÇÏ´Â ¹æ¹ý
2,876
À¥¼­¹ö ip È®ÀÎ
2,875
À¥È£½ºÆÃÀÇ Àý´ë°æ·Î¸¦ È®ÀÎ
2,874
input ÀÔ·Â ÇÊµå ¾ÕµÚ °ø¹é ½Ç½Ã°£ Á¦°Å
2,873
Placeholder Æ÷Ä¿½º½Ã °¨Ãß±â
2,872
MySQL Áߺ¹µÈ µ¥ÀÌÅ͸¦ »èÁ¦
2,871
MySQL Áߺ¹ µ¥ÀÌÅÍ È®ÀÎ
2,870
sessionStorage.getItem ¿Í sessionStorage.setItem
2,869
Á¦ÀÌÄõ¸® ·£´ýÀ¸·Î ¹è°æ»ö º¯°æ
2,868
preg match¿¡ °üÇÑ Á¤±Ô½Ä
2,867
Stream an audio file with MediaPlayer ¿Àµð¿À ÆÄÀÏ ½ºÆ®¸®¹Ö Çϱâ
2,866
Audio Streaming PHP Code
2,865
PHP $ SERVER ȯ°æ º¯¼ö Á¤¸®
2,864
Vimeo (ºñ¸Þ¿À) API ¸¦ »ç¿ëÇÏ¿© Ç÷¹À̾î ÄÁÆ®·ÑÇϱâ
2,863
iframe »ç¿ë½Ã ÇÏ´Ü¿¡ ¹ß»ýÇÏ´Â °ø¹é Á¦°Å¹æ¹ý
2,862
¾ÆÀÌÇÁ·¹ÀÓ(iframe) Àüüȭ¸é °¡´ÉÇÏ°Ô Çϱâ
2,861
ºÎÆ®½ºÆ®·¦(bootstrapk)¿¡¼­ »ç¿ëÇÏ´Â class¸í Á¤¸®
2,860
ºÎÆ®½ºÆ®·¦ CSS
2,859
Å©·Ò¿¡¼­ ¸¶Áø Á¶Àý
2,858
PHP ÇöÀç ÆäÀÌÁöÀÇ µµ¸ÞÀθíÀ̳ª urlµîÀÇ Á¤º¸ ¾Ë¾Æ¿À±â
2,857
PHP preg match all()
2,856
PHP ·Î À¥ÆäÀÌÁö ±Ü¾î¿À±â ¸ðµç ¹æ¹ý ÃÑÁ¤¸®!
2,855
[PHP] ¿ø°ÝÁö ÆÄÀÏ ÁÖ¼Ò ³ëÃâ ¾ÈÇÏ°í curl·Î ´Ù¿î·Îµå ¹Þ±â
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.