Friday, 30 January 2015

How can I overload an element type in a xml schema file?



We are using xmlbeans to generate java source code base on the schema file, and I'm trying to achieve a scenario where two classes which only differ in one aspect share the same interface, in order to avoid repeating code:



public interface Request extends Message {
RequestType getType();
// this would be an interface
RequestData data;
Authentication getAuth();
// etc...
}

public interface RequestOne() extends Request {
RequestOneData data;
}

public interface RequestTwo() extends Request {
RequestTwoData data;
}


The problem is, I don't know how to achieve this my xml schema, as the data element is required to be between RequestType and Authentication, as such:



<request-one>
<type>...</type>
<data>
<1>a</1>
<2>b</2>
</data>
<auth>...</auth>
</request-one>

<request-two>
<type>...</type>
<data>
<1>a</1>
<2>b</2>
<3>c</3>
</data>
<auth>...</auth>
</request-two>


The problem is, I can't use <xsd:extension base="tns:Request"> in RequestA and RequestB, as changing the type of element data is invalid. Is there another way I can achieve this with an xml schema and xmlbeans?


No comments:

Post a Comment