Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2008

Tip: Looking for answers? Try searching our database.

tab delimited to xml

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 18 Mar 2008 22:47 GMT
I'm trying to use XmlCsvReader that is quoted in example
http://msdn2.microsoft.com/en-us/library/aa302293.aspx on msdn. I'm using
VS2008. When I compile I receive an error for

using Microsoft.XML ;

Is there a better way to do this in VS2008 or is there something I need to
install to
make "using Microsoft.XML" available?
Martin Honnen - 19 Mar 2008 12:56 GMT
> I'm trying to use XmlCsvReader that is quoted in example
> http://msdn2.microsoft.com/en-us/library/aa302293.aspx on msdn. I'm using
[quoted text clipped - 5 lines]
> install to
> make "using Microsoft.XML" available?

I tried to download the sample but it seems no longer to be available. I
am not sure what Microsoft.XML refers to, it looks a bit like an MSXML
program id but I can't imagine why a .NET solution would use MSXML.

Signature

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

Dave - 19 Mar 2008 14:56 GMT
i forgot to mention in my post that I simply want to convert a tab delimited
file to xml. Can you refer me to an example or an explanation that will help
with this task?

> > I'm trying to use XmlCsvReader that is quoted in example
> > http://msdn2.microsoft.com/en-us/library/aa302293.aspx on msdn. I'm using
[quoted text clipped - 9 lines]
> am not sure what Microsoft.XML refers to, it looks a bit like an MSXML
> program id but I can't imagine why a .NET solution would use MSXML.
Martin Honnen - 19 Mar 2008 15:48 GMT
> i forgot to mention in my post that I simply want to convert a tab delimited
> file to xml. Can you refer me to an example or an explanation that will help
> with this task?

It should not be that difficult, try this C#/.NET 2.0 code:

        static void TabToXml(string fileIn, string fileOut)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(fileOut, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("root");
                foreach (string line in File.ReadAllLines(fileIn))
                {
                    writer.WriteStartElement("row");
                    foreach (string col in line.Split(new char[] { '\t' }))
                    {
                        writer.WriteElementString("col", col);
                    }
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }

When applied to this tab delimited input
a    b    c
1    2    3
X    Y    Z
it creates the following result:
<?xml version="1.0" encoding="utf-8"?>
<root>
  <row>
    <col>a</col>
    <col>b</col>
    <col>c</col>
  </row>
  <row>
    <col>1</col>
    <col>2</col>
    <col>3</col>
  </row>
  <row>
    <col>X</col>
    <col>Y</col>
    <col>Z</col>
  </row>
</root>
Signature


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

Dave - 19 Mar 2008 22:00 GMT
Thanks.

> > i forgot to mention in my post that I simply want to convert a tab delimited
> > file to xml. Can you refer me to an example or an explanation that will help
[quoted text clipped - 47 lines]
>    </row>
> </root>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.