rhymix/classes/xml/XmlGenerator.class.php
Kijin Sung dfa1e93c79 Remove unnecessary header and footer from class files
- 아래에 이미 author 언급이 있으므로 중복되는 저작권 표기는 제거
- 클래스 하단에 불필요한 end of file 표시 제거 (파일 하나에 클래스 하나씩이므로
  파일이 중간에 끊겼다면 클래스가 닫히지 않아 쉽게 알 수 있음)
2023-01-30 23:52:23 +09:00

73 lines
1.3 KiB
PHP

<?php
/**
* XmlGenerator class
* @author NAVER (developers@xpressengine.com)
* @package /classes/xml
* @version 0.1
*/
class XmlGenerator
{
/**
* object change to xml
* @param object $xml
* @return string
*/
function obj2xml($xml)
{
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
foreach($xml as $nodeName => $nodeItem)
{
$buff .= $this->_makexml($nodeItem);
}
return $buff;
}
/**
* object change to xml
* @param object $node node in xml object
* @return string
*/
function _makexml($node)
{
$body = '';
foreach($node as $key => $value)
{
switch($key)
{
case 'node_name' : break;
case 'attrs' : {
$attrs = '';
if(isset($value))
{
foreach($value as $attrName => $attrValue)
{
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue, ENT_COMPAT | ENT_HTML401, 'UTF-8', false));
}
}
}
break;
case 'body' :
$body = $value;
break;
default : {
if(is_array($value))
{
foreach($value as $idx => $arrNode)
{
$body .= $this->_makexml($arrNode);
}
}
else if(is_object($value))
{
$body = $this->_makexml($value);
}
}
}
}
return sprintf('<%s%s>%s</%s>' . "\n", $node->node_name, $attrs, $body, $node->node_name);
}
}