Elgg  Version 1.9
ElggXMLElement.php
Go to the documentation of this file.
1 <?php
12  private $_element;
13 
19  public function __construct($xml) {
20  if ($xml instanceof SimpleXMLElement) {
21  $this->_element = $xml;
22  } else {
23  // do not load entities
24  $disable_load_entities = libxml_disable_entity_loader(true);
25 
26  $this->_element = new SimpleXMLElement($xml);
27 
28  libxml_disable_entity_loader($disable_load_entities);
29  }
30  }
31 
35  public function getName() {
36  return $this->_element->getName();
37  }
38 
42  public function getAttributes() {
43  //include namespace declarations as attributes
44  $xmlnsRaw = $this->_element->getNamespaces();
45  $xmlns = array();
46  foreach ($xmlnsRaw as $key => $val) {
47  $label = 'xmlns' . ($key ? ":$key" : $key);
48  $xmlns[$label] = $val;
49  }
50  //get attributes and merge with namespaces
51  $attrRaw = $this->_element->attributes();
52  $attr = array();
53  foreach ($attrRaw as $key => $val) {
54  $attr[$key] = $val;
55  }
56  $attr = array_merge((array) $xmlns, (array) $attr);
57  $result = array();
58  foreach ($attr as $key => $val) {
59  $result[$key] = (string) $val;
60  }
61  return $result;
62  }
63 
67  public function getContent() {
68  return (string) $this->_element;
69  }
70 
74  public function getChildren() {
75  $children = $this->_element->children();
76  $result = array();
77  foreach ($children as $val) {
78  $result[] = new ElggXMLElement($val);
79  }
80 
81  return $result;
82  }
83 
90  public function __get($name) {
91  switch ($name) {
92  case 'name':
93  return $this->getName();
94  break;
95  case 'attributes':
96  return $this->getAttributes();
97  break;
98  case 'content':
99  return $this->getContent();
100  break;
101  case 'children':
102  return $this->getChildren();
103  break;
104  }
105  return null;
106  }
107 
114  public function __isset($name) {
115  switch ($name) {
116  case 'name':
117  return $this->getName() !== null;
118  break;
119  case 'attributes':
120  return $this->getAttributes() !== null;
121  break;
122  case 'content':
123  return $this->getContent() !== null;
124  break;
125  case 'children':
126  return $this->getChildren() !== null;
127  break;
128  }
129  return false;
130  }
131 }
__get($name)
Override ->
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
__isset($name)
Override isset.
$key
Definition: summary.php:34
if($item->getSelected()) $children
Definition: item.php:21
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7
__construct($xml)
Creates an ElggXMLParser from a string or existing SimpleXMLElement.