diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-12-02 11:03:25 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-12-04 11:40:33 +0100 |
commit | c80ec91f281419e59b3fd2ce2668278e440d6768 (patch) | |
tree | 4200c178705818e9a61dc9141e5f6683c54ef840 /lib | |
parent | ba52c996cf81781d752748986c761667f59691a3 (diff) | |
download | nextcloud-server-c80ec91f281419e59b3fd2ce2668278e440d6768.tar.gz nextcloud-server-c80ec91f281419e59b3fd2ce2668278e440d6768.zip |
switch to different parsing implementation to get xml attributes properly handled
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/app/infoparser.php | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index e220fb40df6..3d2b42765aa 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -47,7 +47,7 @@ class InfoParser { if ($xml == false) { return null; } - $array = json_decode(json_encode((array)$xml), TRUE); + $array = $this->xmlToArray($xml, false); if (is_null($array)) { return null; } @@ -86,4 +86,59 @@ class InfoParser { return $array; } + + /** + * @param \SimpleXMLElement $xml + * @return array + */ + function xmlToArray($xml) { + if (!$xml->children()) { + return (string)$xml; + } + + $array = array(); + foreach ($xml->children() as $element => $node) { + $totalElement = count($xml->{$element}); + + if (!isset($array[$element])) { + $array[$element] = ""; + } + /** + * @var \SimpleXMLElement $node + */ + + // Has attributes + if ($attributes = $node->attributes()) { + $data = array( + '@attributes' => array(), + ); + if (!count($node->children())){ + $value = (string)$node; + if (!empty($value)) { + $data['@value'] = (string)$node; + } + } else { + $data = array_merge($data, $this->xmlToArray($node)); + } + foreach ($attributes as $attr => $value) { + $data['@attributes'][$attr] = (string)$value; + } + + if ($totalElement > 1) { + $array[$element][] = $data; + } else { + $array[$element] = $data; + } + // Just a value + } else { + if ($totalElement > 1) { + $array[$element][] = $this->xmlToArray($node); + } else { + $array[$element] = $this->xmlToArray($node); + } + } + } + + return $array; + } } |