This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
During some work at auto-generating xml schemas/xml data from Java Class structures here; http://cvs.adligo.org/viewvc/xml_io/ http://cvs.adligo.org/viewvc/models_core/ I have come across a problem that I believe can NOT be solved by the current xml schema specification. In a nutshell if I have a java interface; interface I_Name { String getName(); } and two impls class MyName { private String name String getName() { return name; } } class YourName { private String name String getName() { return name; } } And a class that contains a collection of these ie; class MyClass { List<I_Name> names = new ArrayList<I_Name>(); public void setName(List<I_Name p) { names.clear(); names.addAll(p); } } To represent YourName or MyName I would want to make the xml look like this; <yourName name="you" /> <myName name="me"/> And for MyClass I would want something like; <myClass> <names> <yourName name="you" /> <myName name="me"/> </names> </myClass> So the problem is that I have the following choices for schemas sequence element; element | group | choice | sequence | any The problem with each is as follows; element this like a java Class so you can extend but no multiple inheritance group this is like a interface for child elements chice this is a list of choices which would work for the two example impls but would NOT allow other schemas to plug into my schema (implement my interface) sequence (the problem recurses) any this is any element (so no restrictions) I have also looked at substitutionGroups to try to solve this problem, but that doesn't seem to work either.
To fix this I suggest adding the following; <sequence> <any-in inGroup="ns:someGroup" inAttributeGroup="ns:someAttributeGroupName" /> </sequence> The element's type would need to contain the group and attribute group if both were present, or just the group if present or just the attribute group if present. This would allow Java-XML to have more of a one to one mapping.
This does seem possible with usage of xsi:type, however I was hoping to do it with out an additional attribute (just through the tag name).
First, pleas note that having got XSD 1.1 out as a Recommendation, the WG currently has no charter to start work on a new version or on requirements for a new version. However, if any work does start, the WG will no doubt look at this. As far as I can see, however, substitution groups should meet your requirement. Declare the content model for MyClass as a sequence of I_Name; declare I_Name as an abstract element with MyName and YourName in its substitution group. Note that XSD 1.1 allows elements to belong to more than one substitution group if you need to model multiple inheritance, though this doesn't necessarily mean of course that every class model you can devise in Java maps trivially to a corresponding XSD schema - that has never been a design aim.
Hi thanks for the quick response. I think I oversimplified my issue a bit in the test case that I gave; I would also need to be able to; 1) Add a List<String> aliases to MyName's attribute (which would make it a complex type ie); <myName name="me"> <aliases> <name>The Organ</name> <name>Hearty</name> </aliases> </myName> But I think either element substitution groups or something like this; http://www.ibm.com/developerworks/library/x-xml11pt2/#listing4 will solve my issue.