0

有没有一种简单的方法可以遍历 xml 文件并使用 php 将所有数据添加到 MYSQL 数据库?

我有一个产品提要,其中包含许多 skus。我想遍历 xml 文件,并为每个 sku 将其数据作为新行添加到数据库中。我还想用脚本同时创建数据库表和必要的列,所以每个xml属性都有一个列。下面是来自 xml 提要的一个 sku 的示例:

<sku>
    <id>9303136</id>
    <name>Midway 3 Tier Towel Holder Nickel Finish</name>
    <description>Space saving storage for kitchen roll, foil and cling film.</description>
    <ean>0000003340714</ean>
    <price>34.00</price>
    <wasPrice/>
    <deliveryBand/>
    <deliveryCost>5.0</deliveryCost>
    <deliveryTime>Delivery usually within 5 weeks or Collect at Store</deliveryTime>
    <deliveryLeadTime>35</deliveryLeadTime>
    <stockAvailability>1</stockAvailability>
    <channel>Both Home Delivery and In Store</channel>
    <buyerCats>
        <catLevel0>KITCHENS</catLevel0>
        <catLevel1>BETTER BUILT KITCHEN ACCE</catLevel1>
        <catLevel2>CHESTNUT</catLevel2>
    </buyerCats>
    <affiliateCats>
        <affiliateCat0>Home & Garden</affiliateCat0>
    </affiliateCats>
    <categoryHierarchy>Hooks & Holders</categoryHierarchy>
    <imageUrl>http://s7g1.scene7.com/is/image/BandQ/0000003340714_001c_v001_zp</imageUrl>
    <thumbnailUrl>http://s7g1.scene7.com/is/image/BandQ/0000003340714_001c_v001_zp?$75x75_generic$=</thumbnailUrl>
    <facets>
        <facet name="dimensionsMetricHeightMm">348.0</facet>
        <facet name="featuresFixingIncl">Yes</facet>
        <facet name="dimensionsMetricWidthMm">300.0</facet>
        <facet name="specificationsProductType">Hooks & Holders</facet>
        <facet name="styleFinish">Nickel Finish</facet>
        <facet name="dimensionsMetricLengthMm">145.0</facet>
    </facets>
    <relatedItems>
        <relatedItem>0000003466872</relatedItem>
        <relatedItem>0000003039601</relatedItem>
    </relatedItems>
    <optionalTags>
        <optionalTag>ROOMS15</optionalTag>
    </optionalTags>
</sku>
4

0 回答 0