Need help in creating a console application to read xml files from a folder and convert them to text file and save them in a separate folder using a xsl file for transformation.
需要帮助创建一个控制台应用程序来从文件夹中读取xml文件并将它们转换为文本文件,并使用xsl文件将它们保存在单独的文件夹中进行转换。
I have tried multiple options but nothing has worked. Below is what I currently have.
我尝试了多种选择但没有任何效果。以下是我目前的情况。
For Each xmlFile As System.IO.FileInfo In xmlFiles
'Do some data processing here
Document = New XmlDocument()
Document.Load(xmlFile.FullName)
navigator = Document.CreateNavigator
Dim reade As XmlReader = XmlReader.Create(xmlFile.FullName)
transformer = New XslCompiledTransform
transformer.Load("C:\Sample_XML_Files\Sample_XML_Files\Testing.xslt")
output = New StringWriter()
transformer.Transform(reade, Nothing, output)
Dim stream As FileStream = New FileStream(xmlFile.DirectoryName + "\Out\" + xmlFile.Name + ".text", FileMode.Create)
Dim writer As StreamWriter = New StreamWriter(stream)
writer.Write(output.ToString)
MessageBox.Show(output.ToString)
writer.Close()
output.Close()
Next
Any help in resolving this will be helpfull.
解决这个问题的任何帮助都会有所帮助。
1 个解决方案
#1
0
Try using the Transform method that just takes the two string arguments, input file and destination file. That way you eliminate all the reader/stream stuff on your end. Public Sub Transform (inputUri As String, resultsFile As String)
尝试使用只接受两个字符串参数,输入文件和目标文件的Transform方法。这样你就可以消除所有读者/流的东西了。 Public Sub Transform(inputUri As String,resultsFile As String)
I assume you've tried the xml transform via the xslt directly via xml notepad or some other interactive xslt processing program that can use microsoft's xslt parser. This would be to elimate the xml/xslt transform itself as the source of the problem.
我假设您已经通过xml记事本直接通过xslt尝试了xml转换,或者其他一些可以使用microsoft的xslt解析器的交互式xslt处理程序。这将使xml / xslt转换本身成为问题的根源。
Alternatively you could use a different xslt engine to do your work.
或者,您可以使用不同的xslt引擎来完成您的工作。
#1
0
Try using the Transform method that just takes the two string arguments, input file and destination file. That way you eliminate all the reader/stream stuff on your end. Public Sub Transform (inputUri As String, resultsFile As String)
尝试使用只接受两个字符串参数,输入文件和目标文件的Transform方法。这样你就可以消除所有读者/流的东西了。 Public Sub Transform(inputUri As String,resultsFile As String)
I assume you've tried the xml transform via the xslt directly via xml notepad or some other interactive xslt processing program that can use microsoft's xslt parser. This would be to elimate the xml/xslt transform itself as the source of the problem.
我假设您已经通过xml记事本直接通过xslt尝试了xml转换,或者其他一些可以使用microsoft的xslt解析器的交互式xslt处理程序。这将使xml / xslt转换本身成为问题的根源。
Alternatively you could use a different xslt engine to do your work.
或者,您可以使用不同的xslt引擎来完成您的工作。