Visual Basic - Conversor XML .csv

Life is soft - evento anual de software empresarial
 
Vista:

Conversor XML .csv

Publicado por Adirane (3 intervenciones) el 27/11/2006 18:25:41
Hola....mi problema es el siguiente, estoy utilizando un código visual basic para transformar un fichero xml a csv, porque la ERP con la que trabajo no permite trabajar con xml. El código es este

'----------
Dim xmlSource
Dim xmlXForm
Dim strErr
Dim strResult

Dim fso , file
Dim strPath
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set xmlSource = CreateObject("MSXML.DOMDocument")
Set xmlXForm = CreateObject("MSXML.DOMDocument")

xmlSource.validateOnParse = True
xmlXForm.validateOnParse = True
xmlSource.async = False
xmlXForm.async = False

xmlSource.Load "c:\pedidocabecera.xml" ' This loads the text that I want to transform
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf
strErr = strErr & xmlSource.parseError.reason & " line: " & xmlSource.parseError.Line & " col: " & xmlSource.parseError.linepos & " text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error loading the XML"
End If

xmlXForm.Load "c:\pedidocabecera.xsl" ' This loads the XSLT transform
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf
strErr = strErr & xmlSource.parseError.reason & " line: " & xmlSource.parseError.Line & " col: " & xmlSource.parseError.linepos & " text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error loading the Transform"
End If

strResult = xmlSource.transformNode(xmlXForm) ' This transforms the data in xmlSource
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf
strErr = strErr & xmlSource.parseError.reason & " line: " & xmlSource.parseError.Line & " col: " & xmlSource.parseError.linepos & " text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error executing the Transform"
End If

Set fso = CreateObject("Scripting.FileSystemObject")
strPath = "c:\pedidocabecera.csv"
' open the file
Set file = fso.opentextfile(strPath, ForWriting, True)
' write the info to the file
file.write strResult
' close and clean up
file.Close

Set file = Nothing
Set fso = Nothing
Set xmlSource = Nothing
Set xmlXForm = Nothing
'----------

Esto trabaja con un fichero xsl en el que le paso los nombres de las etiquetas xml, que es el siguiente

<?xml version="1.0"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="registro">
<xsl:text/>"<xsl:value-of select="normalize-space(@Pedido)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@Temporada)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@Codigo)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@RefCliente)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@FechaPedido)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@FechaEntrega)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@FechaTope)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@FechaValor)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@Cliente)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@Observaciones)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@DireccionEntrega)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@CPOEntrega)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@PoblacionEntrega)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@TipoPedido)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@TarifaAplicada)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@DescuentoComercial)"/>";"<xsl:text/>
<xsl:value-of select="normalize-space(@DescuentoPPago)"/>" <xsl:text/>
</xsl:template>
</xsl:stylesheet>

¿Cuál es el problema? Pues que necesito automatizar el proceso, digamos que yo voy a tener una carpeta en un ftp en la que me van a pasar pedidos. El problema es darle la ruta al fichero de lo que tiene que transformar, porque cada vez que alguien envia pedido en la carpeta del ftp se me crea una carpeta que tiene como nombre, la fecha y la hora del momento en que se pasa. Es decir, yo tendría una carpeta dento de la cual podría haber otra llamada 271106_1047 y 271106_1805...y que este script me transformase lo de dentro de las dos carpetas. Algún caracter comodín????
Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder