Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Convert xml file to plain text file

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 6/14/2007 2:04:00 PM

Hans wrote:

> And then call (from VB6 where doc is a domdocument that contains the xml 
> document, stylesheet is also a domdocument holding the styleheet and 
> MyStream is a Adodb.Stream object)
> doc.transformNodeToObject stylesheet, MyStream
> MyStream.SaveToFile("c.\test.txt")
> 
> 
> but the file is always empty.

Do you call Open on the stream first?
Here is a complete VBScript program that works for me:

Dim XmlDoc, XsltProc, Template, Sheet
Set XmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
Set Sheet = CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
Set Template = CreateObject("Msxml2.XslTemplate.3.0")
Sheet.async = False
If Sheet.load("test2007061401Xsl.xml") Then
   XmlDoc.async = False
   If XmlDoc.load("test2007061401.xml") Then
     Template.stylesheet = Sheet
     Set XsltProc = Template.CreateProcessor
     XsltProc.input = XmlDoc
     Set Stream = CreateObject("ADODB.Stream")
     Stream.Open
     Stream.Type = 1
     XsltProc.output = Stream
     XsltProc.Transform
     Stream.SaveToFile "test2007061401Result.txt"
     Stream.Close
   Else
     WScript.Echo "Error parsing XML: " & XmlDoc.parseError.reason
   End If
Else
   WScript.Echo "Error parsing stylesheet: " & Sheet.parseError.reason
End If

XML input is your sample, stylesheet is similar to yours with some 
addition to output line breaks:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" />
<xsl:template match="/">
     <xsl:apply-templates  select="HEADER/ROWS/ROW"/>
</xsl:template>

<xsl:template match="HEADER/ROWS/ROW">
     <xsl:value-of select="TEXT" />
     <xsl:if test="position() != last()">
       <xsl:value-of select="'&#13;&#10;'"/>
     </xsl:if>
</xsl:template>

</xsl:stylesheet>

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent