본문 바로가기

웹프로그래밍/PHP

PHP XML CDATA Parsing

반응형

define(INFO, $path."info.xml");

$infoXML = new DOMDocument();

$infoXML->load(INFO);

$category = getXMLTextContent($infoXML, "group");

 

function getXMLTextContent($xml, $field){
 $vars = $xml->getElementsByTagName($field);
 foreach($vars as $var){
  foreach($var->childNodes as $child) {
   if ($child->nodeType == XML_CDATA_SECTION_NODE) {
    return $child->textContent;
   }
  }
 }
}

 

반응형