0

誰かが私を助けてくれることを願っています。私はこれで非常に新しいです。XSDスキーマを取得してXMLデータを複数のSQLテーブルにダンプすることは可能かどうか疑問に思いました(sql:relation attributeなどを使用して)。

1つのテーブルで問題がないことがわかっているので、データを2つにダンプできるかどうか疑問に思いました。1つのXSDスキーマでこれを実行できると便利ですが、2番目のテーブルのXMLで2つのパスを作成する必要がありますか?

助けてくれてありがとう。


スキーマ自体は次のとおりです。

<?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 &amp; nightwear</item>
        <item id="3">Women</item>
        <item id="2">Clothing</item>
        <item id="1">Clothing, shoes &amp; accessories</item>
      </category>
    </product>
</products>
</feed>

ご覧のとおり、ProductDataProductDataCategoryの2つのテーブルにダンプしようとします。要素に格納されているものだけが<item>、後者のテーブル(フィールドカテゴリ)に配置されます。

エラーメッセージは次のとおりです。

エラー:「カテゴリ」で関係が必要です

どうしてか分かりません :(

これを機能させるための支援に感謝します!

4

2 に答える 2

1

ジャンゴ、

DBVis ( http://www.dbvis.com/ ) のようなものを試して、データベース内のすべての関係を視覚的に表現し、生成された図と xsd を一致させることに取り組んでみませんか。これにより、これらすべての関係を確実に取得できます。

非常に単純なデータベースのスクリーンショットの例については、こちらを参照してください - http://www.dbvis.com/products/dbvis/doc/main/doc/ug/databaseExplorer/images/genericschemaview.png

はるかに大きなデータベースでもうまく機能することを保証できます。

うまくいけば、これは役に立ちます。

于 2010-12-01T13:53:08.990 に答える
1

一括インポートを行う場合は、XSD ファイルで SQL 関係を定義する必要がある場合があります。同様の問題に遭遇しました(これは単なる例であり、XSDに固有のものではありません):

  <xs:annotation>
    <xs:appinfo>
      <sql:relationship name="Detail"
                        parent="Product"
                        parent-key="ProductID"
                        child="Details"
                        child-key="ProductID" 
                        />
      <sql:relationship name="ProductFiles"
                       parent="Product"
                       parent-key="ProductID"
                       child="Files"
                       child-key="ProductID" 
                        />
      <sql:relationship name="ProductToList"
                        parent="Product"
                        parent-key="ProductID"
                        child="ProductList"
                        child-key="ProductID"
                        />
      <sql:relationship name="ListToProduct"
                        parent="ProductList"
                        parent-key="ID"
                        child="ProductListProduct"
                        child-key="ProductListID"
                        />
    </xs:appinfo>
  </xs:annotation>
于 2010-11-29T18:24:11.580 に答える