开发者

XSD schema abstract type problem

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="SETOBSERVATIONSCHEDULEA开发者_如何学CCTION"/>
            <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?


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.


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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜