Reputation: 31
I have a problem with an xsd schema file.
I have this abstract complex type on my schema:
<complexType name="Action" abstract="true">
<sequence>
<element name="actionType">
<complexType>
<choice>
<element name="ALARMACTION"/>
<element name="REPORTDATAACTION"/>
<element name="ENABLEOBSERVATIONACTION"/>
<element name="DISABLEOBSERVATIONACTION"/>
<element name="SETOBSERVATIONSCHEDULEACTION"/>
<element name="VERIFYOVERTIMEACTION"/>
</choice>
</complexType>
</element>
</sequence>
</complexType>
This is a concrete implementation of Action abstract element:
<complexType name="AlarmAction">
<complexContent>
<extension base="ref:Action">
<sequence>
<element name="alarmCode" type="integer"/>
<element name="report" type="string"/>
</sequence>
</extension>
</complexContent>
</complexType>
This element references the abstract Action element:
<complexType name="Conclusion">
<sequence>
<element minOccurs="0" name="observationSet" type="ref:ObservationSet"/>
<element name="action" type="ref:Action"/>
</sequence>
</complexType>
I got an error with this xml instance:
<Conclusion>
<observationSet>
<observationPhenomenum>HIGH_HEARTBEAT</observationPhenomenum>
</observationSet>
<action>
<actionType>
<ENABLEOBSERVATIONACTION></ENABLEOBSERVATIONACTION>
</actionType>
<observationId>1</observationId>
<observationId>2</observationId>
</action>
</Conclusion>
The error on netbeans is this: cvc-type.2: The type definition cannot be abstract for element action. [104]
Can someone help me?
Upvotes: 3
Views: 20174
Reputation: 616
While validation of request xml against wsdl you have to include following attributes
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" use this in the root element
on abstract type element
<abstractElement name="XYZ" xsi:type="Name of your instance" > </abstractElement>
Upvotes: 0
Reputation: 61
You can use an abstract complexType as element type, but the user writing a XML instance document with this schema has to state the type of the element.
For your example this means you have to write it as follows:
<Conclusion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="conclusion.xsd">
<observationSet>
<observationPhenomenum>HIGH_HEARTBEAT</observationPhenomenum>
</observationSet>
<action xsi:type="AlarmAction">
<actionType>
<ENABLEOBSERVATIONACTION></ENABLEOBSERVATIONACTION>
</actionType>
<alarmCode>10</alarmCode>
<report>Whatever</report>
</action>
</Conclusion>
For more information hav a look here: http://pic.dhe.ibm.com/infocenter/wci/v6r0m0/index.jsp?topic=%2Fcom.ibm.websphere.cast_iron.doc%2Fmap_Selecting_a_Substitution_Type.html
Upvotes: 6
Reputation: 21658
I assume that the schema is valid; you do have somewhere a definition for a global element with the local name "Conclusion", and a non-abstract, complex type deriving from Action, with repeating observationId elements (e.g. XYZAction).
Your problem then is rezolved if you add xsi:type="XYZAction" as an attribute to your action element. Again, the attribute value must match the name of a non-abstract type, that derives from the abstract Action.
My advice to you is when in doubt, use a tool to generate a sample XML for the scenario you have in mind. I am using QTAssistant, since it allows me to easily build any scenario imaginable using simple drag and drop of XML Schema elements.
Upvotes: 5