无法从xsd生成类。未定义的complexType用作复杂类型扩展的基础

时间:2014-11-19 07:59:36

标签: xml class xsd

我正在尝试从下面提到的xsd生成一个类,但是我得到以下异常:

未定义的complexType' http://ws.orbitz.com/schemas/v3/Hotel:BasicStayDetails'用作复杂类型扩展的基础。

Xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
            targetNamespace="http://ws.orbitz.com/schemas/v3/Hotel"
            xmlns:com="http://ws.orbitz.com/schemas/v3/Common"
            xmlns="http://ws.orbitz.com/schemas/v3/Hotel">

    <xsd:include schemaLocation="hotel_common.xsd"/>

    <xsd:import namespace="http://ws.orbitz.com/schemas/v3/Common" schemaLocation="../common/common.xsd"/>

    <xsd:element name="HotelShoppingResponse">
        <xsd:complexType>
            <xsd:complexContent>
                <xsd:extension base="com:CommonResponseValues">
                    <xsd:sequence>
                        <xsd:element name="PaginationKey" type="xsd:string" minOccurs="0" maxOccurs="1">
                            <xsd:annotation>
                                <xsd:documentation xml:lang="en">
                                    Key to identify multiple hotel search requests performed for pagination. This key
                                    will be used for tracking the client sessions for the same search criteria on
                                    Pagination.
                                </xsd:documentation>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="Location" type="com:Location" minOccurs="0" maxOccurs="1"/>
                        <xsd:element name="StayDetails" type="ShopStayDetails" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="Hotels" type="Hotels" minOccurs="1" maxOccurs="1"/>
                        <xsd:element name="Areas" type="com:Areas" minOccurs="0" maxOccurs="1"/>
                    </xsd:sequence>
                </xsd:extension>
            </xsd:complexContent>
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="ShopStayDetails">
        <xsd:complexContent>
            <xsd:extension base="BasicStayDetails"/>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="Hotels">
        <xsd:sequence>
            <xsd:element name="Hotel" type="ShopHotel" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="href" type="xsd:anyURI" use="required"/>
        <xsd:attribute name="hasMoreHotels" type="xsd:boolean" use="optional"/>
        <xsd:attribute name="responseCount" type="com:Number" use="required"/>
        <xsd:attribute name="totalCount" type="com:Number" use="required">
            <xsd:annotation>
                <xsd:documentation>
                    This attribute reflects all the hotels that matches the search criteria
                    regardless of availability.
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="ShopHotel">
        <xsd:sequence>
            <xsd:element name="Details" type="ShopDetails" minOccurs="0" maxOccurs="1"/>
            <xsd:element name="Rooms" type="ShopRooms" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="ShopDetails">
        <xsd:complexContent>
            <xsd:extension base="BasicDetails">
                <xsd:sequence>
                    <xsd:element name="Areas" type="com:NeighborhoodAreas" minOccurs="0" maxOccurs="1">
                        <xsd:annotation>
                            <xsd:documentation xml:lang="en">Optional element - Contains list of neighborhood location
                                ids.
                            </xsd:documentation>
                        </xsd:annotation>
                    </xsd:element>
                </xsd:sequence>
                <xsd:attribute name="availability" type="xsd:string" use="optional">
                    <xsd:annotation>
                        <xsd:documentation xml:lang="en">Optional element to distinguish the availability status of a
                            hotel as Available or Unknown.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="ShopRooms">
        <xsd:complexContent>
            <xsd:extension base="BasicRooms">
                <xsd:sequence>
                    <xsd:element name="RoomRates" type="RoomRates" minOccurs="0" maxOccurs="4"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

</xsd:schema>

帮助将不胜感激。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

更正了

的路径
schemaLocation="../common/common.xsd"/>

并添加缺少的xsd。 来自Visual studio:

  1. 在解决方案资源管理器中添加xsd。
  2. 右键单击root xsd并单击generate xml
  3. 将xml转换为class。