diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 75c0ca3e8..fc27ea911 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -46,11 +46,14 @@ class XmlExporter extends AbstractExporter */ public function exportClassMetadata(ClassMetadataInfo $metadata) { - $xml = new \SimpleXmlElement(""); + $xml = new \SimpleXmlElement(""); - $xml->addAttribute('xmlns', 'http://doctrine-project.org/schemas/orm/doctrine-mapping'); + /*$xml->addAttribute('xmlns', 'http://doctrine-project.org/schemas/orm/doctrine-mapping'); $xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); - $xml->addAttribute('xsi:schemaLocation', 'http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd'); + $xml->addAttribute('xsi:schemaLocation', 'http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd');*/ if ($metadata->isMappedSuperclass) { $root = $xml->addChild('mapped-superclass'); @@ -128,6 +131,21 @@ class XmlExporter extends AbstractExporter $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType; } + if ($id) { + foreach ($id as $field) { + $idXml = $root->addChild('id'); + $idXml->addAttribute('name', $field['fieldName']); + $idXml->addAttribute('type', $field['type']); + if (isset($field['columnName'])) { + $idXml->addAttribute('column', $field['columnName']); + } + if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { + $generatorXml = $idXml->addChild('generator'); + $generatorXml->addAttribute('strategy', $idGeneratorType); + } + } + } + if ($fields) { foreach ($fields as $field) { $fieldXml = $root->addChild('field'); @@ -163,21 +181,6 @@ class XmlExporter extends AbstractExporter } } - if ($id) { - foreach ($id as $field) { - $idXml = $root->addChild('id'); - $idXml->addAttribute('name', $field['fieldName']); - $idXml->addAttribute('type', $field['type']); - if (isset($field['columnName'])) { - $idXml->addAttribute('column', $field['columnName']); - } - if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { - $generatorXml = $idXml->addChild('generator'); - $generatorXml->addAttribute('strategy', $idGeneratorType); - } - } - } - foreach ($metadata->associationMappings as $name => $associationMapping) { if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) { $associationMappingXml = $root->addChild('one-to-one'); @@ -305,47 +308,16 @@ class XmlExporter extends AbstractExporter } /** - * Code originally taken from - * http://recurser.com/articles/2007/04/05/format-xml-with-php/ - * - * @param string $simpleXml + * @param \SimpleXMLElement $simpleXml * @return string $xml */ private function _asXml($simpleXml) { - $xml = $simpleXml->asXml(); + $dom = new \DOMDocument('1.0', 'UTF-8'); + $dom->loadXML($simpleXml->asXML()); + $dom->formatOutput = true; - // add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries) - $xml = preg_replace('/(>)(<)(\/*)/', "$1\n$2$3", $xml); - - // now indent the tags - $token = strtok($xml, "\n"); - $result = ''; // holds formatted version as it is built - $pad = 0; // initial indent - $matches = array(); // returns from preg_matches() - - // test for the various tag states - while ($token !== false) { - // 1. open and closing tags on same line - no change - if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) { - $indent = 0; - // 2. closing tag - outdent now - } else if (preg_match('/^<\/\w/', $token, $matches)) { - $pad = $pad - 4; - // 3. opening tag - don't pad this one, only subsequent tags - } elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) { - $indent = 4; - // 4. no indentation needed - } else { - $indent = 0; - } - - // pad the line with the required number of leading spaces - $line = str_pad($token, strlen($token)+$pad, ' ', STR_PAD_LEFT); - $result .= $line . "\n"; // add to the cumulative result, with linefeed - $token = strtok("\n"); // get the next token - $pad += $indent; // update the pad size for subsequent lines - } + $result = $dom->saveXML(); return $result; } } \ No newline at end of file