易趣导出列表XML结构。将DTD转换为XSD

时间:2012-11-22 11:25:54

标签: xml xsd dtd ebay

任何人都可以从Ebay了解这个XML文件结构吗?

http://pages.ebay.co.uk/help/sell/export-structure.html

我不认为这是一个有效的架构,并且很难理解XML的结构。有人能想出来吗?

我需要基于此构建一个导入脚本,但无法从任何地方获取正确的XML文件样本。

非常感谢

修改

我发现它是一个DTD架构。因此,我需要以某种方式转换为xsd。

2 个答案:

答案 0 :(得分:1)

您的链接所指向的ebay的DTD无效,因此我不得不进行一些更正。

可能导致问题的一个更正是Published元素有两个声明。我删除了自timestamp未声明后有timestamp个孩子的声明。

更正后的DTD,生成的XSD和示例实例如下。

XSD和样本实例是使用oXygen XML Editor生成的(我强烈推荐)。

这至少应该让你开始......

原始DTD (已修复)

<!ELEMENT       ebay (StoreExport)>

<!ELEMENT       StoreExport (Settings, Products)>


<!ELEMENT   Settings (Published)>

<!-- The timestamp reflects when the Items have last changed. -->
<!ELEMENT       Published     EMPTY>
<!ATTLIST       Published
                timestamp     CDATA #REQUIRED>

<!ELEMENT       Products     (Product*)>


<!ELEMENT       Product      (Description,
                                Caption,
                                Url,
                                EndTime,
                                Category,
                                EndNodeCategory,
                                BuyItNow?,
                                ListingFormat,
                                Orderable,
                                SiteCurrency,
                                Pricing,
                                Availability?,
                                Quantity,
                                GalleryPicture?,
                                Site,
                                Country)>
<!ATTLIST       Product
        Id            CDATA        #REQUIRED>


<!ELEMENT   Description      (#PCDATA)>
<!ELEMENT   Caption          (#PCDATA)>
<!ELEMENT   Url              (#PCDATA)>
<!ELEMENT   EndTime          (#PCDATA)>
<!ELEMENT   Category         (#PCDATA)>
<!ELEMENT   EndNodeCategory  (#PCDATA)>
<!ELEMENT   BuyItNow         (#PCDATA)>
<!ELEMENT   ListingFormat    (#PCDATA)>
<!ELEMENT   Orderable        (#PCDATA)>
<!ELEMENT   SiteCurrency     (#PCDATA)>
<!ELEMENT   Pricing          (BasePrice,BuyItNowPrice?,ShippingCost?)>
<!ELEMENT   Availability     (#PCDATA)>
<!ELEMENT   Quantity         (#PCDATA)>
<!ELEMENT   GalleryPicture   (#PCDATA)>
<!ELEMENT   Site             (#PCDATA)>
<!ELEMENT   Country          (#PCDATA)>

<!ELEMENT   BasePrice        (#PCDATA)>
<!ELEMENT   BuyItNowPrice    (#PCDATA)>
<!ELEMENT   ShippingCost     (#PCDATA)>

XSD (ebay.xsd)

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="ebay" type="StoreExport"/>
    <xs:complexType name="StoreExport">
        <xs:sequence>
            <xs:element ref="StoreExport"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="StoreExport">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Settings"/>
                <xs:element ref="Products"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Settings" type="Published"/>
    <!-- The timestamp reflects when the Items have last changed. -->
    <xs:complexType name="Published">
        <xs:sequence>
            <xs:element ref="Published"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="Published">
        <xs:complexType>
            <xs:attributeGroup ref="attlist.Published"/>
        </xs:complexType>
    </xs:element>
    <xs:attributeGroup name="attlist.Published">
        <xs:attribute name="timestamp" use="required"/>
    </xs:attributeGroup>
    <xs:element name="Products">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" maxOccurs="unbounded" ref="Product"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Product">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Description"/>
                <xs:element ref="Caption"/>
                <xs:element ref="Url"/>
                <xs:element ref="EndTime"/>
                <xs:element ref="Category"/>
                <xs:element ref="EndNodeCategory"/>
                <xs:element minOccurs="0" ref="BuyItNow"/>
                <xs:element ref="ListingFormat"/>
                <xs:element ref="Orderable"/>
                <xs:element ref="SiteCurrency"/>
                <xs:element ref="Pricing"/>
                <xs:element minOccurs="0" ref="Availability"/>
                <xs:element ref="Quantity"/>
                <xs:element minOccurs="0" ref="GalleryPicture"/>
                <xs:element ref="Site"/>
                <xs:element ref="Country"/>
            </xs:sequence>
            <xs:attributeGroup ref="attlist.Product"/>
        </xs:complexType>
    </xs:element>
    <xs:attributeGroup name="attlist.Product">
        <xs:attribute name="Id" use="required"/>
    </xs:attributeGroup>
    <xs:element name="Description" type="xs:string"/>
    <xs:element name="Caption" type="xs:string"/>
    <xs:element name="Url" type="xs:string"/>
    <xs:element name="EndTime" type="xs:string"/>
    <xs:element name="Category" type="xs:string"/>
    <xs:element name="EndNodeCategory" type="xs:string"/>
    <xs:element name="BuyItNow" type="xs:string"/>
    <xs:element name="ListingFormat" type="xs:string"/>
    <xs:element name="Orderable" type="xs:string"/>
    <xs:element name="SiteCurrency" type="xs:string"/>
    <xs:element name="Pricing">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="BasePrice"/>
                <xs:element minOccurs="0" ref="BuyItNowPrice"/>
                <xs:element minOccurs="0" ref="ShippingCost"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Availability" type="xs:string"/>
    <xs:element name="Quantity" type="xs:string"/>
    <xs:element name="GalleryPicture" type="xs:string"/>
    <xs:element name="Site" type="xs:string"/>
    <xs:element name="Country" type="xs:string"/>
    <xs:element name="BasePrice" type="xs:string"/>
    <xs:element name="BuyItNowPrice" type="xs:string"/>
    <xs:element name="ShippingCost" type="xs:string"/>
</xs:schema>

示例XML实例

<ebay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="file:/C:/ebay.xsd">
    <StoreExport>
        <Settings>
            <Published timestamp="timestamp0"/>
        </Settings>
        <Products>
            <Product Id="Id0">
                <Description>Description0</Description>
                <Caption>Caption0</Caption>
                <Url>Url0</Url>
                <EndTime>EndTime0</EndTime>
                <Category>Category0</Category>
                <EndNodeCategory>EndNodeCategory0</EndNodeCategory>
                <BuyItNow>BuyItNow0</BuyItNow>
                <ListingFormat>ListingFormat0</ListingFormat>
                <Orderable>Orderable0</Orderable>
                <SiteCurrency>SiteCurrency0</SiteCurrency>
                <Pricing>
                    <BasePrice>BasePrice0</BasePrice>
                    <BuyItNowPrice>BuyItNowPrice0</BuyItNowPrice>
                    <ShippingCost>ShippingCost0</ShippingCost>
                </Pricing>
                <Availability>Availability0</Availability>
                <Quantity>Quantity0</Quantity>
                <GalleryPicture>GalleryPicture0</GalleryPicture>
                <Site>Site0</Site>
                <Country>Country0</Country>
            </Product>
            <Product Id="Id1">
                <Description>Description1</Description>
                <Caption>Caption1</Caption>
                <Url>Url1</Url>
                <EndTime>EndTime1</EndTime>
                <Category>Category1</Category>
                <EndNodeCategory>EndNodeCategory1</EndNodeCategory>
                <BuyItNow>BuyItNow1</BuyItNow>
                <ListingFormat>ListingFormat1</ListingFormat>
                <Orderable>Orderable1</Orderable>
                <SiteCurrency>SiteCurrency1</SiteCurrency>
                <Pricing>
                    <BasePrice>BasePrice1</BasePrice>
                    <BuyItNowPrice>BuyItNowPrice1</BuyItNowPrice>
                    <ShippingCost>ShippingCost1</ShippingCost>
                </Pricing>
                <Availability>Availability1</Availability>
                <Quantity>Quantity1</Quantity>
                <GalleryPicture>GalleryPicture1</GalleryPicture>
                <Site>Site1</Site>
                <Country>Country1</Country>
            </Product>
        </Products>
    </StoreExport>
</ebay>

答案 1 :(得分:0)

James Clark的trang是一种多格式架构转换器。如前所述,ebay的DTD需要修复 - “已发布”的两个元素声明;如果'Published'的第一个适用,则'timestamp'没有元素声明;没有'PCDATA'声明的值(可能应该是'CDATA');没有'#CDATA'声明的内容(应该是'#PCDATA') - 在应用任何转换器之前。