Friday, November 14, 2008

X2svg: how to create diagrams (in the XSD parser)?

For some simple stuff it is easy to create diagrams with x2svg - here is an example from the test suite:

$ sh run.sh -c :pdf test-src/resources/sample.xsd root


This creates a PDF version of sample.xsd along with a SVG one (technically speaking, it creates a SVG version and converts it to PDF afterwards), where the root of the tree is the element root. There are no limits, so the whole tree with all its children is shown.

sample.png


But how to tackle more complex things?

The XSD-Parser has some options that we will have a look at:


  • -d n: this limits the depth of the tree to n, where a depth of 0 means the root element only and 1 means one level of children:


    sample1.png


  • -st : This option tells the parser that the given root element is not an element, but a type.

  • -lt : If this element is given, then elements of an given type are not filled with the content of the type, but the type name is specified:


    $ sh run.sh -c :png test-src/resources/inheritance.xsd parent-type -lt

    inheritance-lt.png


    Note, that there is currently a little display bug.



Those options allow you to create already good quality structural content from your schema files - see e.g. Part 2 and Part 4 of my RHQ plugin development series.

No comments: