Generating PHP Classes from MagicDraw XML.
MagicDraw is an awesome UML modeling tool. However, it currently doesn't export PHP class files. So I went ahead and created a PHP script that uses XSL to generate PHP class files from a MagicDraw XML project file.

View the sample UML class diagram.

View the resulting PHP class file.

View the script source.

View the MagicDraw XML project file.

Download the zipped script and sample files here.

A Quick How To
  1. Download the files.
  2. $ unzip mdtophp-1.1.zip
  3. $ cd mdtophp-1.1/
  4. Edit the first line in generate_php_class.sh to point to your php executable. Currently: #!/usr/bin/php -qC
  5. $ chmod u+x generate_php_class.sh
  6. $ ./generate_php_class.sh sample.xml md_to_php.xsl Person
    Watch the generated PHP class file scroll by.
  7. OR:
    $ ./generate_php_class.sh sample.xml md_to_php.xsl Person > Person.php
    To create a generated PHP class file.
Command Line Arguments

$ ./generate_php_class.sh sample.xml md_to_php.xsl Person
  1. generate_php_class.sh is the script.

  2. sample.xml is an unzipped MagicDraw project file.

  3. md_to_php.xsl is the XSLT for creating the PHP class file. Edit this file to add your own formatting.

  4. Person is a class name of the class in the MagicDraw project file that you want to generate a file for.
Resources

XSLT XMI MagicDraw UML PHP Versions

  • Linux RedHat 7.2
  • PHP 4.2.1
  • Sablotron 0.90-3
  • MagicDraw 5.5
  • XML 1.0
  • XSL 1.0
  • XMI 1.1
Feedback

Feedback is welcome. If you enhance the XSLT or the script please let me know. The same goes for bugs. Email Charlie@Tizac.com.