I have an XML Schema which I am parsing in JavaScript and then packing that as an object to pass to one of my backend servers.
The schema is like
<complexType name='Test'>
<sequence>
<element name='testField' type='string'/>
<element name='typeSpecificSetting' type='tns:TypeSpecific'/>
</sequence>
</complexType>
<complexType name="TypeSpecific">
<choice>
<element name='A' type='tns:ATYPE'/>
<element name='B' type='tns:BTYPE'/>
<element name='C' type='tns:CTYPE'/>
<element name='D' type='tns:DTYPE'/>
</choice>
</complexType>
<complexType name="ATYPE">
<element name='testATYPEField' type='string'/>
</complexType>
<complexType name="BTYPE">
<element name='testBTYPEField' type='string'/>
</complexType>
I am reading the xml schema and then trying to construct my request object.
request = {
testField: t1,
typeSpecificSetting: t2
}
How can I construct the request object for choice? Depending upon type, I have to pack either of ATYPE or BTYPE or CTYPE or DTYPE objects? How can I achieve this?