Mary Ryllo
Mary Ryllo

Reputation: 2371

How to design xsd schema for two common elements with different input data?

I need an advice how to design xsd schema to represent objects.

I have a such interface

public interface Validator{
     boolean validate(Q query);   
}

And I have some implementations -

public class SimpleValidator implements Validator{

     private R param;

     public boolean validate(Q Query){
          //some logic with using param   
     }

     public void setParam(R param){
         this.param = param;
     }
}


public class AnotherValidator implements Validator{

     private Data data1;
     private Data data1;

     public boolean validate(Q Query){
          //some logic with using data1 and data2   
     }

     public void setData1(Data data1){
         this.data1 = data1;
     }

     public void setData2(Data data2){
         this.data2 = data2;
     }
}

I have such decision -

I create root element - <xsd:element name="validator" type="validatorType"/>

And such elements -

<xsd:element name="simpleValidator" type="simpleValidatorType"  substitutionGroup="validator"/>

<xsd:element name="anotherValidator" type="anotherValidatorType"  substitutionGroup="validator"/>

Now I can use tags simpleValidator and anotherValidator in the place where is needing validator. Example -

<anotherValidator>
     <data1 value="value1"/>
     <data2 value="value2"/>
</anotherValidator>

The problem is, that I want to use only tag validator. As example, I want something like this -

<validator type="simpleValidator>
     //simpleValidator data
</validator>

<validator type="anotherValidator>
     //anotherValidator data
</validator>

Upvotes: 1

Views: 505

Answers (1)

Asraful
Asraful

Reputation: 1290

I think this can be done using Runtime Polymorphism via xsi:type and Abstract Types I found a related question also : May be helpful.

In one of my project i was dellign with , but there are different type of address namely shippingAddress, billingAddress ..we used this techniqe to solve our problem.

Upvotes: 2

Related Questions