我希望有人能帮助我。我对此很新。我想知道是否有可能获得XSD架构将XML数据转储到多个 SQL表(使用sql:relation attribute
等)。编写一个XSD架构将XML数据放入SQL表
一个表没有问题,所以我只是想知道是否有可能将数据转储为两个。能够用一个XSD Schema做到这一点很好,但是我必须对第二个表的XML进行两次传递吗?
感谢您的任何帮助。
下面是模式本身:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<!-- Skimlinks/Everyfeed schema -->
<!-- definition of simple elements -->
<xs:element name="title" type="xs:string" sql:field="ProductName"/>
<xs:element name="url" type="xs:string" sql:field="ProductURL"/>
<xs:element name="image_url" type="xs:string" sql:field="ImageURL"/>
<xs:element name="currency" type="xs:string" sql:field="currency"/>
<xs:element name="price" type="xs:string" sql:field="Price"/>
<xs:element name="merchant" type="xs:string" sql:field="Brand" default=" " />
<xs:element name="description" type="xs:string" sql:field="Description" default=" "/>
<xs:element name="item" type="xs:string" sql:field="Category" />
<!-- definition of attributes -->
<xs:attribute name="id" type="xs:string" sql:field="SKU" />
<!-- definition of complex elements -->
<xs:element name="category" sql:relation="ProductDataCategory">
<xs:complexType>
<xs:sequence>
<xs:element ref="item" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="product" sql:relation="ProductData">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="url"/>
<xs:element ref="image_url"/>
<xs:element ref="currency"/>
<xs:element ref="price"/>
<xs:element ref="merchant"/>
<xs:element ref="description"/>
<xs:element ref="category"/>
</xs:sequence>
<xs:attribute ref="id" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="products" sql:is-constant="1">
<xs:complexType>
<xs:sequence>
<xs:element ref="product" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="everyFeed" sql:is-constant="1">
<xs:complexType>
<xs:sequence>
<xs:element ref="products" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
下面是我们要导入的XML的例子:
<?xml version='1.0' encoding='utf-8'?>
<feed version="2">
<numFound>7985</numFound>
<products>
<product id="18639|216623247">
<title>Trouser</title>
<url>http://www.products.com/trousers/trouser/</url>
<image_url>http://www.images.co.uk/images/big/4d624426.jpg</image_url>
<verified_image>True</verified_image>
<currency>GBP</currency>
<price>1000</price>
<prev_price>1000</prev_price>
<firstseen>2010-10-27T00:00:00Z</firstseen>
<lastseen>2010-10-27T00:00:00Z</lastseen>
<merchant id="20748">Yours Clothing</merchant>
<by>Yours Clothing</by>
<description></description>
<category>
<item id="9">Lounge & nightwear</item>
<item id="3">Women</item>
<item id="2">Clothing</item>
<item id="1">Clothing, shoes & accessories</item>
</category>
</product>
</products>
</feed>
正如你所看到的,它试图转储到两个表: ProductData and ProductDataCategory。只有存储在<item>
元素中的内容应该放在后面的表中(在字段类别中)。
的错误消息写着:
Error: Relationship expected on 'category'
我不知道为什么:(
感谢您得到这个工作的任何援助
@Django - 我已经被重新绑定,因为这是对XML模式的特定于Microsoft的扩展 – Anon 2010-11-18 18:22:18
您需要提供有关您要执行的操作的更多详细信息。你如何使用这种模式将数据批量加载到单个表中? – 2010-11-18 20:08:26
嗨,约翰,这里有更详细的信息:http://stackoverflow.com/questions/3373104/problem-during-sql-bulk-load – 2010-11-19 09:16:26