converting .xml to a comma delimited text file

B

Bernie Yaeger

Is there a way to convert or copy a .xml file to a comma delimited text file
using vb .net?

Thanks for any help.

Bernie Yaeger
 
J

Jeff Johnson [MVP: VB]

Is there a way to convert or copy a .xml file to a comma delimited text file
using vb .net?

That's an extremely vague question. Could you provide more detail,
specifically what the XML currently looks like and what you want the CSV to
look like?
 
C

Cor Ligthert

That's an extremely vague question. Could you provide more detail,
specifically what the XML currently looks like and what you want the CSV to
look like?
Is that a question Jeff, when you have a XMLdocument you have to use the
xmlReader and when it is a dataset you can use the readXML.

That is the only important point in my opinion.
For the last one I have a simple generic sample.

By the way Bernie is a very regular to this dotNet newsgroup he helps often.

Cor
 
B

Bernie Yaeger

Hi Jeff,

Tx for your reply.

I am trying to take a table within a dataset and get it into a comma
delimited .txt file. If I try to do this with a stream or textstream using,
say, a 25000 row table, it takes quite some time. If I use the writexml
method, it's incredibly fast. So I thought - what if I first write it to
xml and then convert it? Ultimately, what I need is a comma delimited
textfile (.txt). Doing the same thing in .csv using interop and the Excel
object, it also takes far too long.

Thanks for any help.

Bernie
 
B

Bernie Yaeger

Hi Cor,

Nice to hear from you again.

The answer is a document, but let me explain more thoroughly.

I am trying to take a table within a dataset and get it into a comma
delimited .txt file. If I try to do this with a stream or textstream using,
say, a 25000 row table, it takes quite some time. If I use the writexml
method, it's incredibly fast. So I thought - what if I first write it to
xml and then convert it? Ultimately, what I need is a comma delimited
textfile (.txt). Doing the same thing in .csv using interop and the Excel
object, it also takes far too long.

Thanks for any help.

Bernie
 
M

Marina

What about using XSLT on the xml that you have? I know XSL is notoriously
slow, but it still be a lot faster then just writing it and formatting it
manually.
 
C

Cor Ligthert

Hi Bernie,

Now I do not understand it anymore, you want to write a table and than read
it

Here is my sample. See what you can do with it.
\\\\
Dim sw As New IO.StreamWriter("C:\Bernie.csv")
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim row As New System.Text.StringBuilder
row.Append("""")
For y As Integer = 0 To ds.Tables(0).Columns.Count - 1
row.Append(ds.Tables(0).Rows(i)(y).tostring)
If y <> ds.Tables(0).Columns.Count - 1 Then
row.Append(""",""")
' if you want it with a tab
' row.Append("""")
' row.Append(chr(09))
' row.Append("""")
Else
row.Append("""")
End If
Next
sw.WriteLine(row.ToString)
Next
sw.Flush()
sw.Close()
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top