Saturday, July 17, 2010

Implementing inheritance in XSDs

this structure:




will generate this Java code:

@XmlType(name = "TAG")
public class TAG {


@XmlRootElement(name = "TAGA")

public class TAGA
    extends TAG
    @XmlElement(name = "TransactionType", required = true)
    protected String transactionType;


This is an excellent way to model in XSD while keeping good OO practices.

You can also factor out in TAG the elements common to all subclasses, exactly as you should do in Java. Be careful with sequence ordering though.

No comments: