Skip to content

Commit d478552

Browse files
author
Alessandro Mattiello
committed
set a prefix for attributes name. Default prefix = '@'
1 parent 21249c9 commit d478552

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

LSS/XML2Array.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
class XML2Array {
4545

4646
private static $xml = null;
47-
private static $encoding = 'UTF-8';
47+
private static $encoding = 'UTF-8';
48+
private static $prefix_attributes = '@';
4849

4950
/**
5051
* Initialize the root XML node [optional]
@@ -92,7 +93,7 @@ private static function &convert($node) {
9293

9394
switch ($node->nodeType) {
9495
case XML_CDATA_SECTION_NODE:
95-
$output['@cdata'] = trim($node->textContent);
96+
$output[static::$prefix_attributes.'cdata'] = trim($node->textContent);
9697
break;
9798

9899
case XML_TEXT_NODE:
@@ -142,7 +143,7 @@ private static function &convert($node) {
142143
}
143144
// if its an leaf node, store the value in @value instead of directly storing it.
144145
if(!is_array($output)) {
145-
$output = array('@value' => $output);
146+
$output = array(static::$prefix_attributes.'value' => $output);
146147
}
147148
$output['@attributes'] = $a;
148149
}

0 commit comments

Comments
 (0)