SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Convert file xml to txt

    Hi all, I need your help.

    I try this ASP code for convert file xml to txt.

    I don't have error but the output is txt file null (0 kB).

    Can you help me?
    Regards

    Code:
    <% 
    
    '----------
      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("MSXML2.DOMDocument.4.0")
      Set xmlXForm = CreateObject("MSXML2.DOMDocument.4.0")
     
      xmlSource.validateOnParse = True
      xmlXForm.validateOnParse = True
      xmlSource.async = False
      xmlXForm.async = False
     
      xmlSource.Load Server.Mappath("\xml\titty.xml")
      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
      End If
     
      xmlXForm.Load Server.Mappath("\xml\testme.xsl")
      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
      End If
       
      strResult = xmlSource.transformNode(xmlXForm)
      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
      End If
     
      Set fso = CreateObject("Scripting.FileSystemObject")
      strPath = Server.Mappath("\xml\testme.txt")
    
      Set file = fso.opentextfile(strPath, ForWriting, True)
    
      file.write strResult
    
      file.Close
     
      Set file = Nothing
      Set fso = Nothing
      Set xmlSource = Nothing
      Set xmlXForm = Nothing
    '----------
    
    %>

  2. #2
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    357
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The way you have error checking written hints that you may have 'on error resume next' error trapping turned on before calling this code snip, and that might be hiding errors in the lines of code that write the new file out.

    If you can remove any on error resume next you may see a pertinent error message pointing you to the problem.

    A guess is the web server account doesn't have write permissions to the output directory.
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon

  3. #3
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks x your help and suggestions: now txt file is successfully generated (3.455 kb).

    But I have new problem, this is the output in the txt file:

    Code:
    4150"
    12.19.27.15"
    mike"
    ON"
    ON"
    mike"
    20w97m1"
    244E4119C5254BB5D184"
    1"
    13222"
    0"
    0"
    I need this output:

    Code:
    4150;12.19.27.15;mike;ON;ON;mike;20w97m1;244E4119C5254BB5D184;1;13222;0;0
    One row for one record of the table mysql. It's possible?

    This is the testme.xsl:

    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
    xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="/">
            <xsl:for-each select="/xml/rs:data/z:row">
                    <xsl:for-each select="@*">
                            <xsl:value-of select="."/>
                    </xsl:for-each>
            </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    Can you help me?
    thanks a lot.

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you may get better results from an XML/XSL group rather than here in a classic ASP forum


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •