MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
msimplexml.class
Ir para a documentação deste ficheiro.
1
<?php
2
7
class
MSimpleXml
8
{
12
var
$xml
;
13
23
function
__construct
($file)
24
{
25
$this->xml = simplexml_load_file($file);
26
}
27
39
private
function
_ToSimpleArray($node, &$array = array(), $k =
''
)
40
{
41
foreach
((array)$node as $key => $var)
42
{
43
$aKey = ($k !=
''
) ? $k .
'.'
. $key : $key;
44
45
if
(is_object($var))
46
{
47
if
(count((array)$var) == 0)
48
{
49
$array[$aKey] =
''
;
50
}
51
else
52
{
53
$this->_ToSimpleArray($var, $array, $aKey);
54
}
55
}
56
elseif (is_array($var))
57
{
58
$array[$aKey] = $var;
59
}
60
else
61
{
62
$array[$aKey] = (string)$var;
63
}
64
}
65
}
66
76
function
ToSimpleArray
(&$array = array(), $node = NULL)
77
{
78
if
($node == NULL)
79
$node =
$this->xml
;
80
81
$this->_ToSimpleArray($node, $array);
82
return
$array;
83
}
84
94
private
function
_ToArray(
$xml
)
95
{
96
if
( is_object(
$xml
) )
97
{
98
if
(get_class(
$xml
) ==
'SimpleXMLElement'
)
99
{
100
$attributes =
$xml
->attributes();
101
102
foreach
($attributes as $k => $v)
103
{
104
if
($v)
105
$a[$k] = (string)$v;
106
}
107
108
$x =
$xml
;
109
$xml
= get_object_vars(
$xml
);
110
}
111
}
112
113
if
(is_array(
$xml
))
114
{
115
if
(count(
$xml
) == 0)
116
return
(
string
)$x;
// for CDATA
117
118
foreach
(
$xml
as $key => $value)
119
{
120
$r[$key] = $this->_ToArray($value);
121
}
122
123
if
(isset($a))
124
$r[
'@'
] = $a;
// Attributes
125
126
return
$r;
127
}
128
return
(
string
)
$xml
;
129
}
130
140
function
ToArray
(&$array = array(), $node = NULL)
141
{
142
if
($node == NULL)
143
$node =
$this->xml
;
144
145
return
$this->_ToArray($node);
146
}
147
157
function
XPath
($argument)
158
{
159
return
$this->xml->xpath($argument);
160
}
161
}
162
?>
MSimpleXml
Definição
msimplexml.class:8
MSimpleXml\XPath
XPath($argument)
Definição
msimplexml.class:157
MSimpleXml\__construct
__construct($file)
Definição
msimplexml.class:23
MSimpleXml\$xml
$xml
Definição
msimplexml.class:12
MSimpleXml\ToSimpleArray
ToSimpleArray(&$array=array(), $node=NULL)
Definição
msimplexml.class:76
MSimpleXml\ToArray
ToArray(&$array=array(), $node=NULL)
Definição
msimplexml.class:140
classes
utils
msimplexml.class
Gerado por
1.10.0