Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Extracting an XML file to CSV or DBF
Message
De
25/03/2006 04:38:43
 
 
À
24/03/2006 13:47:02
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01107438
Message ID:
01107614
Vues:
22
>>I have a requirement to Import an XML file (which can have 3 tables) with No Schema and to export it to a CSV or DBf file
>>I've tried the VFP forums but it would appear that VFP can't easily do this:
>>XmToCursor will do it for xml (wuth only 1 Table) without Schema
>>XMLAdapter will do it for Multiple files but needs a schema
>>
>>Dot net does recognise the file ok because If I do a File...Open, it reads in the XML file perfectly.
>>
>>Are there any utiliities in Dot Net that can perform the File ..Open programatically .
>>
>>Regards,
>>Gerard
>
>Gerard,
>
>Do you need to import the data into anything, or can you do a direct conversion XML -> CSV ?
>
>If you only need the conversion, an XSLT transformation is a good solution. Here is a sample that I dug up: http://www.stylusstudio.com/xmldev/200404/post60210.html
>
><?xml version="1.0" encoding="ISO-8859-1"?>
><Inventory>
>  <Line>
>   <ItemNumber>line</ItemNumber>
>   <Description>desc</Description>
>   <Quantity>quan</Quantity>
>   <Date>date</Date>
>  </Line>
>  <Line>
>   <ItemNumber>1</ItemNumber>
>   <Description>Oak chairs</Description>
>   <Quantity>6</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>2</ItemNumber>
>   <Description>Dining tables</Description>
>   <Quantity>1</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>3</ItemNumber>
>   <Description>Folding chairs</Description>
>   <Quantity>4</Quantity>
>   <Date>29 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>4</ItemNumber>
>   <Description>Couch</Description>
>   <Quantity>1</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>5</ItemNumber>
>   <Description>Overstuffed chair</Description>
>   <Quantity>1</Quantity>
>   <Date>30 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>6</ItemNumber>
>   <Description>Ottoman</Description>
>   <Quantity>1</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>7</ItemNumber>
>   <Description>Floor lamp</Description>
>   <Quantity>1</Quantity>
>   <Date>20 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>8</ItemNumber>
>   <Description>Oak bookshelves</Description>
>   <Quantity>1</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>9</ItemNumber>
>   <Description>Computer desk</Description>
>   <Quantity>1</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>10</ItemNumber>
>   <Description>Folding tables</Description>
>   <Quantity>3</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>11</ItemNumber>
>   <Description>Oak writing desk</Description>
>   <Quantity>1</Quantity>
>   <Date>28 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>12</ItemNumber>
>   <Description>Table lamps</Description>
>   <Quantity>5</Quantity>
>   <Date>26 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>13</ItemNumber>
>   <Description>Pine night tables</Description>
>   <Quantity>3</Quantity>
>   <Date>26 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>14</ItemNumber>
>   <Description>Oak dresser</Description>
>   <Quantity>1</Quantity>
>   <Date>30 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>15</ItemNumber>
>   <Description>Pine dressers</Description>
>   <Quantity>1</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
>  <Line>
>   <ItemNumber>16</ItemNumber>
>   <Description>Pine armoire</Description>
>   <Quantity>1</Quantity>
>   <Date>31 Dec 2004</Date>
>  </Line>
></Inventory>
>
>C:\Hacks\examples>cat csv.xsl
><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
><xsl:output method="text"/>
>
><xsl:template match="Inventory">
>  <xsl:apply-templates select="Line"/>
></xsl:template>
>
><xsl:template match="Line">
>  <xsl:for-each select="*">
>   <xsl:value-of select="."/>
>   <xsl:if test="position() != last()">
>    <xsl:value-of select="','"/>
>   </xsl:if>
>  </xsl:for-each>
>  <xsl:text>
></xsl:text>
></xsl:template>
>
></xsl:stylesheet>
>
>
>
>The process itself is quite simple. Load the XSL stylesheet and perform the transformation:
>
>Dim xslt As New XslTransform()
>xslt.Load(stylesheetfilename)
>xslt.Transform(inputfile.xml, outputfile.csv|txt, Nothing)
>
But then there's no need to use .NET - the same thing can be done in VFP
Regards,
Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform