将XML作为单个表/表转换为数据集/CSV [英] Converting XML into Dataset/CSV as a Single Table/Sheet

查看:90
本文介绍了将XML作为单个表/表转换为数据集/CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个每周的库存/产品更新,可以从供应商处以XML格式通过电子邮件发送给我,而我正努力将其转换/将数据提取到我可以使用的数据集或CSV文件中,以用于我在VB.NET中编写的另一个程序,用于更新我的在线购物车的产品/库存清单.

XML的格式如下:

Hi All,

I have a weekly stock/product update that gets emailed to me from my suppliers in XML Format, and I''m struggling to get it converted/the data extracted into a Dataset or a CSV file that I can work with, to use in another program I''ve written up in VB.NET that updates my online shopping cart''s product/stock list.

The format of the XML is like this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<StockCatalogue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DickerData_StockCatalogue.xsd" generated="2010-07-05T06:00:00">
  <StockItem>
    <StockCode>AF513A</StockCode>
    <StockType>Item</StockType>
    <QtyOnHand>0</QtyOnHand>
    <StockDescription>
      <StockDescriptionShort>HP 3PH 16A INTL Mod PDU</StockDescriptionShort>
      <StockDescriptionLong></StockDescriptionLong>
      <StockPrimaryCategory>SERVERS</StockPrimaryCategory>
      <StockSecondaryCategory>HP SERVER OPTION</StockSecondaryCategory>
      <StockTertiaryCategory>PDU</StockTertiaryCategory>
    </StockDescription>
    <StockVendor>
      <Vendor>HP</Vendor>
      <VendorPartCode>AF513A</VendorPartCode>
    </StockVendor>
    <Pricing>
      <RetailPriceEx>726.36</RetailPriceEx>
      <RetailPriceInc>799.00</RetailPriceInc>
      <ResellerPriceEx>600.25</ResellerPriceEx>
      <ResellerPriceInc>660.27</ResellerPriceInc>
      <CurrentPriceEx>600.25</CurrentPriceEx>
      <CurrentPriceInc>660.27</CurrentPriceInc>
    </Pricing>
    <StockSpecs>
    </StockSpecs>
  </StockItem>



有人可以请我帮忙还是帮我编写源代码,以便将上述所有数据都放入一个我可以使用的单一表中,因为目前看来,尝试使用时最多可以创建8个不同的表将其转换为数据集

非常感谢您的帮助

干杯,
Ray.



Can someone please give me or assist me in writing up the source code to be able to get all the above data into a Single Table that I can work with, as at the moment, it seems to be creating up to 8 different tables when trying to convert it into a dataset

Your help is much appreciated

Cheers,
Ray.

推荐答案

查看XSD的XML文件声明:

Look at your XML file''s declaration for the XSD:

xsi:noNamespaceSchemaLocation="DickerData_StockCatalogue.xsd"


数据中有多个表".如果您要使用代码,则必须使用代码手动创建单个表,或者使用某种XSL转换来做到这一点.


The data has multiple ''tables'' in it. You will have to manually create a single table using code if that''s what you''re wanting or use some kind of XSL transformation to do so.


安德鲁

感谢您的回复...

您能在VB.NET中显示如何吗?源代码会很棒!

干杯,
Ray.
Hi Andrew

Thanks for the reply...

Are you able to please show how in VB.NET? Source code would be great!

Cheers,
Ray.


如果有帮助...这是XSD的代码...

< pre><< pre lang ="xml">?xml version =&"1.0& quot; encoding =&"utf-8&"?& gt;
< xs:schema xmlns:xs =&"http://www.w3.org/2001/XMLSchema"
& lt; xs:element name =& quot; StockItem& quot;& gt;
& lt; xs:complexType& gt;
< xs:sequence maxOccurs =&"unbounded&"& gt;
& lt; xs:element name =& quot; StockCode& quot; type =&"xs:string&"/& gt;
& lt; xs:element name =& quot; StockType& quot;<
& lt; xs:simpleType& gt;
& lt; xs:restriction base =&"xs:string& gt;"
< xs:枚举值=&"Bundle&"/>
& lt; xs:枚举值=& quot; Item& quot;/& gt;
& lt;/xs:restriction& gt;
& lt;/xs:simpleType& gt;
& lt//xs:element& gt;
< xs:元素名称=& quot; StockBundle& quot; minOccurs =&"0"& gt;
& lt; xs:complexType& gt;
< xs:sequence maxOccurs =&"unbounded&"& gt;
& lt; xs:element name =& quot; BundleComponentStockCode& quot; type =&"xs:string&"/& gt;
& lt;/xs:sequence& gt;
& lt;/xs:complexType& gt;
& lt//xs:element& gt;
< xs:element name =& quot; QtyOnHand& quot; type =&"xs:integer&"/& gt;
& lt; xs:element name =& quot; StockDescription& quot;<
& lt; xs:complexType& gt;
& lt; xs:sequence& gt;
& lt; xs:element name =& quot; StockDescriptionShort& quot; type =&"xs:string&"/& gt;
& lt; xs:element name =& quot; StockDescriptionLong& quot; type =&"xs:string&"/& gt;
< xs:元素名称=& quot; StockPrimaryCategory& quot; type =&"xs:string&"/& gt;
< xs:元素名称=& quot; StockSecondaryCategory& quot; type =&"xs:string&"/& gt;
< xs:元素名称=& quot; StockTertiaryCategory& quot; type =&"xs:string&"/& gt;
& lt;/xs:sequence& gt;
& lt;/xs:complexType& gt;
& lt//xs:element& gt;
& lt; xs:element name =& quot; StockVendor& quot;<
& lt; xs:complexType& gt;
& lt; xs:sequence& gt;
< xs:element name =& quot;供应商& quot; type =&"xs:string&"/& gt;
& lt; xs:element name =& quot; VendorPartCode& quot; type =&"xs:string&"/& gt;
& lt;/xs:sequence& gt;
& lt;/xs:complexType& gt;
& lt//xs:element& gt;
& lt; xs:element name =& quot;定价& gt;
& lt; xs:complexType& gt;
& lt; xs:sequence& gt;
< xs:元素名称=& quot; RetailPriceEx& quot; type =&"xs:decimal&"/& gt;
& lt; xs:element name =& quot; RetailPriceInc& quot; type =&"xs:decimal&"/& gt;
< xs:element name =& quot; ResellerPriceEx& quot; type =&"xs:decimal&"/& gt;
< xs:element name =& quot; ResellerPriceInc& quot; type =&"xs:decimal&"/& gt;
< xs:元素名称=& quot; PromoPriceStart& quot; type =&"xs:date&" minOccurs =& quot; 0 amp"/& gt;
& lt; xs:element name =& quot; PromoPriceEnd& quot; type =&"xs:date&" minOccurs =& quot; 0 amp"/& gt;
< xs:元素名称=&"CurrentPriceEx& quot; type =&"xs:decimal&"/& gt;
< xs:元素名称=& quot; CurrentPriceInc& quot; type =&"xs:decimal&"/& gt;
& lt;/xs:sequence& gt;
& lt;/xs:complexType& gt;
& lt//xs:element& gt;
& lt; xs:element name =& quot; StockSpecs& quot;<
& lt; xs:complexType& gt;
& lt; xs:sequence& gt;
& lt; xs:element name =& quot; SpecCategory& quot; type =&"xs:string&" minOccurs =& quot; 0 amp"/& gt;
& lt; xs:element name =& quot; StockSpecItem& quot; minOccurs =&"0" maxOccurs =&"unbounded&"& gt;
& lt; xs:complexType& gt;
& lt; xs:sequence& gt;
& lt; xs:element name =& quot; SpecName& quot; type =&"xs:string&"/& gt;
& lt; xs:element name =& quot; SpecValue& quot; type =&"xs:string&"/& gt;
& lt;/xs:sequence& gt;
& lt;/xs:complexType& gt;
& lt//xs:element& gt;
& lt;/xs:sequence& gt;
& lt;/xs:complexType& gt;
& lt//xs:element& gt;
& lt;/xs:sequence& gt;
& lt;/xs:complexType& gt;
& lt//xs:element& gt;
& lt; xs:element name =& quot; StockCatalogue& quot;<
& lt; xs:complexType& gt;
< xs:sequence maxOccurs =&"unbounded&"& gt;
& lt; xs:element ref =& quot; StockItem& quot;/& gt;
& lt;/xs:sequence& gt;
& lt; xs:属性名称=&生成的& quot; type =&"xs:dateTime&"/& gt;
& lt;/xs:complexType& gt;
& lt//xs:element& gt;
& lt;/xs:schema& gt;</pre>
</pre>
If it helps... here''s the XSD''s code...

<pre><<pre lang="xml">?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
&lt;xs:element name=&quot;StockItem&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence maxOccurs=&quot;unbounded&quot;&gt;
&lt;xs:element name=&quot;StockCode&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;StockType&quot;&gt;
&lt;xs:simpleType&gt;
&lt;xs:restriction base=&quot;xs:string&quot;&gt;
&lt;xs:enumeration value=&quot;Bundle&quot;/&gt;
&lt;xs:enumeration value=&quot;Item&quot;/&gt;
&lt;/xs:restriction&gt;
&lt;/xs:simpleType&gt;
&lt;/xs:element&gt;
&lt;xs:element name=&quot;StockBundle&quot; minOccurs=&quot;0&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence maxOccurs=&quot;unbounded&quot;&gt;
&lt;xs:element name=&quot;BundleComponentStockCode&quot; type=&quot;xs:string&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;xs:element name=&quot;QtyOnHand&quot; type=&quot;xs:integer&quot;/&gt;
&lt;xs:element name=&quot;StockDescription&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;StockDescriptionShort&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;StockDescriptionLong&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;StockPrimaryCategory&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;StockSecondaryCategory&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;StockTertiaryCategory&quot; type=&quot;xs:string&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;xs:element name=&quot;StockVendor&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;Vendor&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;VendorPartCode&quot; type=&quot;xs:string&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;xs:element name=&quot;Pricing&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;RetailPriceEx&quot; type=&quot;xs:decimal&quot;/&gt;
&lt;xs:element name=&quot;RetailPriceInc&quot; type=&quot;xs:decimal&quot;/&gt;
&lt;xs:element name=&quot;ResellerPriceEx&quot; type=&quot;xs:decimal&quot;/&gt;
&lt;xs:element name=&quot;ResellerPriceInc&quot; type=&quot;xs:decimal&quot;/&gt;
&lt;xs:element name=&quot;PromoPriceStart&quot; type=&quot;xs:date&quot; minOccurs=&quot;0&quot;/&gt;
&lt;xs:element name=&quot;PromoPriceEnd&quot; type=&quot;xs:date&quot; minOccurs=&quot;0&quot;/&gt;
&lt;xs:element name=&quot;CurrentPriceEx&quot; type=&quot;xs:decimal&quot;/&gt;
&lt;xs:element name=&quot;CurrentPriceInc&quot; type=&quot;xs:decimal&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;xs:element name=&quot;StockSpecs&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;SpecCategory&quot; type=&quot;xs:string&quot; minOccurs=&quot;0&quot;/&gt;
&lt;xs:element name=&quot;StockSpecItem&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element name=&quot;SpecName&quot; type=&quot;xs:string&quot;/&gt;
&lt;xs:element name=&quot;SpecValue&quot; type=&quot;xs:string&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;xs:element name=&quot;StockCatalogue&quot;&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence maxOccurs=&quot;unbounded&quot;&gt;
&lt;xs:element ref=&quot;StockItem&quot;/&gt;
&lt;/xs:sequence&gt;
&lt;xs:attribute name=&quot;generated&quot; type=&quot;xs:dateTime&quot;/&gt;
&lt;/xs:complexType&gt;
&lt;/xs:element&gt;
&lt;/xs:schema&gt;</pre>
</pre>


这篇关于将XML作为单个表/表转换为数据集/CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆