diff --git a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
index 0ad0b19576..a3d264e189 100644
--- a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
+++ b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
@@ -63,18 +63,20 @@ class XmlUtilsTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider getDataForConvertDomToArray
*/
- public function testConvertDomToArray($expected, $xml)
+ public function testConvertDomToArray($expected, $xml, $root = false, $checkPrefix = true)
{
$dom = new \DOMDocument();
- $dom->loadXML(''.$xml.'');
+ $dom->loadXML($root ? $xml : ''.$xml.'');
- $this->assertSame($expected, XmlUtils::convertDomElementToArray($dom->documentElement));
+ $this->assertSame($expected, XmlUtils::convertDomElementToArray($dom->documentElement, $checkPrefix));
}
public function getDataForConvertDomToArray()
{
return array(
array(null, ''),
+ array('bar', 'bar'),
+ array(array('bar' => 'foobar'), '', true),
array(array('foo' => null), ''),
array(array('foo' => 'bar'), 'bar'),
array(array('foo' => array('foo' => 'bar')), ''),
@@ -85,6 +87,9 @@ class XmlUtilsTest extends \PHPUnit_Framework_TestCase
array(array('foo' => array(array('foo' => 'bar'), array('foo' => 'text'))), ''),
array(array('foo' => array('foo' => array('bar', 'text'))), 'text'),
array(array('foo' => 'bar'), 'bar'),
+ array(array('foo' => 'text'), 'text'),
+ array(array('foo' => array('bar' => 'bar', 'value' => 'text')), 'text', false, false),
+ array(array('attr' => 1, 'b' => 'hello'), 'hello2', true),
);
}
diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php
index 8ab8225df5..9317e15e7c 100644
--- a/src/Symfony/Component/Config/Util/XmlUtils.php
+++ b/src/Symfony/Component/Config/Util/XmlUtils.php
@@ -111,15 +111,20 @@ class XmlUtils
*
* * The nested-tags are converted to keys (bar)
*
- * @param \DomElement $element A \DomElement instance
+ * @param \DomElement $element A \DomElement instance
+ * @param Boolean $checkPrefix Check prefix in an element or an attribute name
*
* @return array A PHP array
*/
- public static function convertDomElementToArray(\DomElement $element)
+ public static function convertDomElementToArray(\DomElement $element, $checkPrefix = true)
{
+ $prefix = (string) $element->prefix;
$empty = true;
$config = array();
foreach ($element->attributes as $name => $node) {
+ if ($checkPrefix && !in_array((string) $node->prefix, array('', $prefix), true)) {
+ continue;
+ }
$config[$name] = static::phpize($node->value);
$empty = false;
}
@@ -131,8 +136,10 @@ class XmlUtils
$nodeValue = trim($node->nodeValue);
$empty = false;
}
+ } elseif ($checkPrefix && $prefix != (string) $node->prefix) {
+ continue;
} elseif (!$node instanceof \DOMComment) {
- $value = static::convertDomElementToArray($node);
+ $value = static::convertDomElementToArray($node, $checkPrefix);
$key = $node->localName;
if (isset($config[$key])) {