Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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>


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.
Posted
Updated 10-Jul-10 10:31am
v2
Comments
Sandeep Mewara 10-Jul-10 16:32pm    
Formatted the code part correctly for you!
RayFrangie 11-Jul-10 10:06am    
Thanks Sandeep... How did you do it? I had it in the code brackets but it didn't work :(

Cheers,
Ray.

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>
 
Share this answer
 
Hi Andrew

Thanks for the reply...

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

Cheers,
Ray.
 
Share this answer
 
Comments
Andrew Rissing 11-Jul-10 11:04am    
I can't really help you here with that. It really depends on what exactly you're wanting to do with the data. The best advice I can give is to google around for "VB.NET DataTable" and go from there.
RayFrangie 11-Jul-10 20:36pm    
Hi Andrew...

All I need is for the StockItem with all it's values below it, be put into a single row, for every StockItem there is in the document. I'll keep looking but havent't had much luck over the past few week...

Cheers,
Ray.
Look at your XML file's declaration for the XSD:

xsi:noNamespaceSchemaLocation="DickerData_StockCatalogue.xsd"

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900