XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
XmlGenerator.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
11 {
12 
18  function obj2xml($xml)
19  {
20  $buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
21 
22  foreach($xml as $nodeName => $nodeItem)
23  {
24  $buff .= $this->_makexml($nodeItem);
25  }
26  return $buff;
27  }
28 
34  function _makexml($node)
35  {
36  $body = '';
37  foreach($node as $key => $value)
38  {
39  switch($key)
40  {
41  case 'node_name' : break;
42  case 'attrs' : {
43  $attrs = '';
44  if(isset($value))
45  {
46  foreach($value as $attrName => $attrValue)
47  {
48  $attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue, ENT_COMPAT | ENT_HTML401, 'UTF-8', false));
49  }
50  }
51  }
52  break;
53  case 'body' :
54  $body = $value;
55  break;
56  default : {
57  if(is_array($value))
58  {
59  foreach($value as $idx => $arrNode)
60  {
61  $body .= $this->_makexml($arrNode);
62  }
63  }
64  else if(is_object($value))
65  {
66  $body = $this->_makexml($value);
67  }
68  }
69  }
70  }
71  return sprintf('<%s%s>%s</%s>' . "\n", $node->node_name, $attrs, $body, $node->node_name);
72  }
73 
74 }
75 /* End of file XmlGenerator.class.php */
76 /* Location: ./classes/xml/XmlGenerator.class.php */