Search code examples
xmlxsddtdebay-design-templates

Ebay export listings XML structure. Convert DTD to XSD


Can anyone make sense of this XML file structure from Ebay?

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

I do not recognise this as a valid schema and am struggling to understand how the XML will be structured. Can anyone figure it out?

I need to build an import script based on this but cannot get a proper XML file sample from anywhere.

Many thanks

EDIT

Ive found out it is a DTD schema. I therefore need to convert to xsd somehow.


Solution

  • The DTD from ebay that your link is pointing to is invalid, so I had to make some corrections.

    The one correction that might cause problems is that there were two declarations for the Published element. I removed the declaration that had a timestamp child since timestamp wasn't declared.

    The corrected DTD, the resulting XSD and a sample instance are below.

    The XSD and sample instance were generated with oXygen XML Editor (which I highly recommend).

    This should at least get you started...

    Original DTD (fixed)

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

    Sample XML Instance

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