sunshine737
asked on
transforming xml to html for n number of xml files in a file directory using vb.net
HI,
i am trying to transform "n" number of files to html.
for example,
i am having some 20 xml files in a directory d:\temp
for all the xml files,i am using single xsl file(export.xsl).
i am trying to build an .exe application which dynamically generates html files for all the xsl files which are present in the directory.
to tranform from xml to html for a single file is:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myXslTransform As XslTransform
myXslTransform = New XslTransform
myXslTransform.Load("d:\tr ansform.xs l")
myXslTransform.Transform(" [name of the xml in the directory d:\temp ]", "[name of the xml file].html")
End Sub
just i want to dynamically generate htmls from the xml.as i dont know the exact number of xml files present in the directory
hope you underrstood the problem
thanks for your help,
regards
i am trying to transform "n" number of files to html.
for example,
i am having some 20 xml files in a directory d:\temp
for all the xml files,i am using single xsl file(export.xsl).
i am trying to build an .exe application which dynamically generates html files for all the xsl files which are present in the directory.
to tranform from xml to html for a single file is:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myXslTransform As XslTransform
myXslTransform = New XslTransform
myXslTransform.Load("d:\tr
myXslTransform.Transform("
End Sub
just i want to dynamically generate htmls from the xml.as i dont know the exact number of xml files present in the directory
hope you underrstood the problem
thanks for your help,
regards
ASKER
hi,
thanks for your reply.
i want the file name without extension.
just thr file name..
if i use f1.name it gives filename.extension
i dont want extension
thanks for your reply.
regards
thanks for your reply.
i want the file name without extension.
just thr file name..
if i use f1.name it gives filename.extension
i dont want extension
thanks for your reply.
regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi,
i am getting exception
"argument outofrange exception" on this line fileName = fileName.Substring(0, fileName.IndexOf(".xsl")). ToString()
regards
i am getting exception
"argument outofrange exception" on this line fileName = fileName.Substring(0, fileName.IndexOf(".xsl")).
regards
Hi vihar123,
I didn't see any error on my program. Could you please show the message which show the value of variable "FileName" before you will pass to the substring function.
Meng
I didn't see any error on my program. Could you please show the message which show the value of variable "FileName" before you will pass to the substring function.
Meng
ASKER
hi,
sorry its my mistake..
your code is perfect.
but i am getting one exception when i am tranforming to html.
Dim dir As String = "d:\"
Dim d As DirectoryInfo = New DirectoryInfo(dir)
Dim fi As FileInfo
Dim myXslTransform As XslTransform
For Each fi In d.GetFiles("*.xml")
myXslTransform = New XslTransform
myXslTransform.Load("expor t.xsl")
myXslTransform.Transform(f ile.Name," filename.h tml") //html file name should be same as of xml file name.
next
i tried like
myXslTransform.Transform(f ile.Name, filename + "html")
but giving xml exception.
any idea?
anyway i give the points.
once again thanks for your reply.
regards
sorry its my mistake..
your code is perfect.
but i am getting one exception when i am tranforming to html.
Dim dir As String = "d:\"
Dim d As DirectoryInfo = New DirectoryInfo(dir)
Dim fi As FileInfo
Dim myXslTransform As XslTransform
For Each fi In d.GetFiles("*.xml")
myXslTransform = New XslTransform
myXslTransform.Load("expor
myXslTransform.Transform(f
next
i tried like
myXslTransform.Transform(f
but giving xml exception.
any idea?
anyway i give the points.
once again thanks for your reply.
regards
Hi vihar123,
I guessed that you might use the full name to pass into the argument of Transform method. So you might use
myXslTransform.Transform(f ile.FullNa me, filename + ".html")
Meng
I guessed that you might use the full name to pass into the argument of Transform method. So you might use
myXslTransform.Transform(f
Meng
ASKER
hi,
i am trying to store the html file in a specific directory.
myXslTransform.Transform(f ile.Name," filename.h tml") //html file name should be same as of xml file name.
the generated html file is stored in the current directory.
how can i store in a specific directory?
i am trying to store the html file in a specific directory.
myXslTransform.Transform(f
the generated html file is stored in the current directory.
how can i store in a specific directory?
Hi vihar123,
Try this. Hopefully it would be helpful :)
Meng
dim strPath as string = "C:\Temp\"
myXslTransform.Transform(f ile.Name,s trPath & "filename.html")
Try this. Hopefully it would be helpful :)
Meng
dim strPath as string = "C:\Temp\"
myXslTransform.Transform(f
ASKER
ASKER
Hi,
when i execute your code,htmls are generated fine.
but when i open the html files,its taking lot of time to open in browser.
sometimes even system is hanged.
do you think that should i need to free any resources which i used.
i mean like closing of files ....like that..
any idea?
regards,
when i execute your code,htmls are generated fine.
but when i open the html files,its taking lot of time to open in browser.
sometimes even system is hanged.
do you think that should i need to free any resources which i used.
i mean like closing of files ....like that..
any idea?
regards,
Hi vihar123,
What is the name of your file ? I sometimes found that if your html file name is weird with some strange character, you will get something wrong once you open.
Meng
What is the name of your file ? I sometimes found that if your html file name is weird with some strange character, you will get something wrong once you open.
Meng
ASKER
hi,
no,the filename is in ascii charcaters only.
actually i am tranforming xml to html as
for each xml
transform to html
next
once the html is created ,when i try to open the html file,its taking some time to open...
what i want to know is after tranformation,should i free the resources ..
i mean normally when i create a file and read,then at the end,i will close the file as
file.close()...
in the sameway,should i do add something for your code...
do u go my point..? :)
no,the filename is in ascii charcaters only.
actually i am tranforming xml to html as
for each xml
transform to html
next
once the html is created ,when i try to open the html file,its taking some time to open...
what i want to know is after tranformation,should i free the resources ..
i mean normally when i create a file and read,then at the end,i will close the file as
file.close()...
in the sameway,should i do add something for your code...
do u go my point..? :)
Hi vihar123,
Actually it seems that the current problem is occurred because of the function to convert from XML to HTML. I suggested you about the way to get the XML File name and translate the name to html file name which is the question you asked.
However, I don't mind to help you but finally I might not know the cause of this problem.
Can you send me the content of html file by posting as a comment ? And also tell me your file name and the path you stored.
Please tell me all I needed because I think all of them affected to your problem.
Thanks :)
Meng
Actually it seems that the current problem is occurred because of the function to convert from XML to HTML. I suggested you about the way to get the XML File name and translate the name to html file name which is the question you asked.
However, I don't mind to help you but finally I might not know the cause of this problem.
Can you send me the content of html file by posting as a comment ? And also tell me your file name and the path you stored.
Please tell me all I needed because I think all of them affected to your problem.
Thanks :)
Meng
Try the following code. You just need to know the list of file under the specified folder.
Meng
Imports System.IO
Dim dir As String = "d:\"
Dim d As DirectoryInfo = New DirectoryInfo(dir)
Dim fi As FileInfo
For Each fi In d.GetFiles("*.xsl")
messagebox.show(fi.Name & vbTab & fi.DirectoryName & vbTab & fi.Length & vbTab & fi.LastWriteTime)
Next