Permalink
Browse files

fix namespace handling in xml loader; it could not handle prefixes

  • Loading branch information...
1 parent 1a60a3c commit 83fc5ff72f1532fbc4d966beb8677db04935d3ba @Tobion Tobion committed Dec 3, 2012
Showing with 22 additions and 25 deletions.
  1. +22 −25 src/Symfony/Component/Routing/Loader/XmlFileLoader.php
View
47 src/Symfony/Component/Routing/Loader/XmlFileLoader.php
@@ -25,6 +25,9 @@
*/
class XmlFileLoader extends FileLoader
{
+ const NAMESPACE_URI = 'http://symfony.com/schema/routing';
+ const SCHEME_PATH = '/schema/routing/routing-1.0.xsd';
+
/**
* Loads an XML file.
*
@@ -70,7 +73,11 @@ public function load($file, $type = null)
*/
protected function parseNode(RouteCollection $collection, \DOMElement $node, $path, $file)
{
- switch ($node->tagName) {
+ if (self::NAMESPACE_URI !== $node->namespaceURI) {
+ return;
+ }
+
+ switch ($node->localName) {
case 'route':
$this->parseRoute($collection, $node, $path);
break;
@@ -84,23 +91,19 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, $pa
$requirements = array();
$options = array();
- foreach ($node->childNodes as $n) {
- if (!$n instanceof \DOMElement) {
- continue;
- }
-
- switch ($n->tagName) {
+ foreach ($node->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $n) {
+ switch ($n->localName) {
case 'default':
- $defaults[$n->getAttribute('key')] = trim($n->nodeValue);
+ $defaults[$n->getAttribute('key')] = trim($n->textContent);
break;
case 'requirement':
- $requirements[$n->getAttribute('key')] = trim($n->nodeValue);
+ $requirements[$n->getAttribute('key')] = trim($n->textContent);
break;
case 'option':
- $options[$n->getAttribute('key')] = trim($n->nodeValue);
+ $options[$n->getAttribute('key')] = trim($n->textContent);
break;
default:
- throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $n->tagName, $file));
+ throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $n->localName, $file));
}
}
@@ -119,7 +122,7 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, $pa
$collection->addCollection($subCollection);
break;
default:
- throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->tagName, $file));
+ throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "route" or "import".', $node->localName, $file));
}
}
@@ -148,23 +151,19 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $definiti
$requirements = array();
$options = array();
- foreach ($definition->childNodes as $node) {
- if (!$node instanceof \DOMElement) {
- continue;
- }
-
- switch ($node->tagName) {
+ foreach ($definition->getElementsByTagNameNS(self::NAMESPACE_URI, '*') as $node) {
+ switch ($node->localName) {
case 'default':
- $defaults[$node->getAttribute('key')] = trim($node->nodeValue);
+ $defaults[$node->getAttribute('key')] = trim($node->textContent);
break;
case 'option':
- $options[$node->getAttribute('key')] = trim($node->nodeValue);
+ $options[$node->getAttribute('key')] = trim($node->textContent);
break;
case 'requirement':
- $requirements[$node->getAttribute('key')] = trim($node->nodeValue);
+ $requirements[$node->getAttribute('key')] = trim($node->textContent);
break;
default:
- throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $node->tagName, $file));
+ throw new \InvalidArgumentException(sprintf('Unknown tag "%s" used in file "%s". Expected "default", "requirement" or "option".', $node->localName, $file));
}
}
@@ -220,12 +219,10 @@ protected function loadFile($file)
*/
protected function validate(\DOMDocument $dom)
{
- $location = __DIR__.'/schema/routing/routing-1.0.xsd';
-
$current = libxml_use_internal_errors(true);
libxml_clear_errors();
- if (!$dom->schemaValidate($location)) {
+ if (!$dom->schemaValidate(__DIR__ . static::SCHEME_PATH)) {
throw new \InvalidArgumentException(implode("\n", $this->getXmlErrors($current)));
}
libxml_use_internal_errors($current);

0 comments on commit 83fc5ff

Please sign in to comment.