Chris@17: appendChild($commandXML = $dom->createElement('command')); Chris@17: $commandXML->setAttribute('id', $command->getName()); Chris@17: $commandXML->setAttribute('name', $command->getName()); Chris@17: Chris@17: // Get the original element and its top-level elements. Chris@17: $originalCommandXML = static::getSingleElementByTagName($dom, $originalDom, 'command'); Chris@17: $originalUsagesXML = static::getSingleElementByTagName($dom, $originalCommandXML, 'usages'); Chris@17: $originalDescriptionXML = static::getSingleElementByTagName($dom, $originalCommandXML, 'description'); Chris@17: $originalHelpXML = static::getSingleElementByTagName($dom, $originalCommandXML, 'help'); Chris@17: $originalArgumentsXML = static::getSingleElementByTagName($dom, $originalCommandXML, 'arguments'); Chris@17: $originalOptionsXML = static::getSingleElementByTagName($dom, $originalCommandXML, 'options'); Chris@17: Chris@17: // Keep only the first of the elements Chris@17: $newUsagesXML = $dom->createElement('usages'); Chris@17: $firstUsageXML = static::getSingleElementByTagName($dom, $originalUsagesXML, 'usage'); Chris@17: $newUsagesXML->appendChild($firstUsageXML); Chris@17: Chris@17: // Create our own elements Chris@17: $newExamplesXML = $dom->createElement('examples'); Chris@17: foreach ($command->getExampleUsages() as $usage => $description) { Chris@17: $newExamplesXML->appendChild($exampleXML = $dom->createElement('example')); Chris@17: $exampleXML->appendChild($usageXML = $dom->createElement('usage', $usage)); Chris@17: $exampleXML->appendChild($descriptionXML = $dom->createElement('description', $description)); Chris@17: } Chris@17: Chris@17: // Create our own elements Chris@17: $newAliasesXML = $dom->createElement('aliases'); Chris@17: foreach ($command->getAliases() as $alias) { Chris@17: $newAliasesXML->appendChild($dom->createElement('alias', $alias)); Chris@17: } Chris@17: Chris@17: // Create our own elements Chris@17: $newTopicsXML = $dom->createElement('topics'); Chris@17: foreach ($command->getTopics() as $topic) { Chris@17: $newTopicsXML->appendChild($topicXML = $dom->createElement('topic', $topic)); Chris@17: } Chris@17: Chris@17: // Place the different elements into the element in the desired order Chris@17: $commandXML->appendChild($newUsagesXML); Chris@17: $commandXML->appendChild($newExamplesXML); Chris@17: $commandXML->appendChild($originalDescriptionXML); Chris@17: $commandXML->appendChild($originalArgumentsXML); Chris@17: $commandXML->appendChild($originalOptionsXML); Chris@17: $commandXML->appendChild($originalHelpXML); Chris@17: $commandXML->appendChild($newAliasesXML); Chris@17: $commandXML->appendChild($newTopicsXML); Chris@17: Chris@17: return $dom; Chris@17: } Chris@17: Chris@17: Chris@17: protected static function getSingleElementByTagName($dom, $parent, $tagName) Chris@17: { Chris@17: // There should always be exactly one '' element. Chris@17: $elements = $parent->getElementsByTagName($tagName); Chris@17: $result = $elements->item(0); Chris@17: Chris@17: $result = $dom->importNode($result, true); Chris@17: Chris@17: return $result; Chris@17: } Chris@17: }