Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5952703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:43:08+00:00 2026-05-22T17:43:08+00:00

I’m wondering if there is an accepted method to convert a tab delimited text

  • 0

I’m wondering if there is an accepted method to convert a tab delimited text file to XML, so that it can be imported in Adobe Flex. I would prefer to use PHP to achieve this.

Thanks

Edit:

The tab delimited text file I am looking to convert is in the format

Refnumber  Location    Name     Age    
123        North America    Steve    32   

And I am looking to convert to

<data>
<refnumber> 123 </refnumber> 
<location> North America </location>
<name> Steve </name>
<age> 32 </age>
</data>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:43:09+00:00Added an answer on May 22, 2026 at 5:43 pm

    You can iterate the file line by line and write the contents with XMLWriter

    XmlWriter Example (demo)

    $xmlWriter = new XMLWriter();
    $xmlWriter->openUri('/path/to/destination.xml');
    $xmlWriter->setIndent(true);
    $xmlWriter->startDocument('1.0', 'UTF-8');
    $xmlWriter->startElement('root');
    
    $tsvFile = new SplFileObject('filename.tsv');
    $tsvFile->setFlags(SplFileObject::READ_CSV);
    $tsvFile->setCsvControl("\t");
    foreach ($tsvFile as $line => $row) {
        if($line > 0) {
            $xmlWriter->startElement('data');
            $xmlWriter->writeElement('refnumber', $row[0]);
            $xmlWriter->writeElement('location', $row[1]);
            $xmlWriter->writeElement('name', $row[2]);
            $xmlWriter->writeElement('age', $row[3]);
            $xmlWriter->endElement();
        }
    }
    $xmlWriter->endElement();
    $xmlWriter->endDocument();
    

    Using the XmlWriter has the added benefit that it will tell you when you are trying to write illegal content for the XML elements. If you know there is only valid data in your tsv file, you can also just use a template and write that to another file.

    Template Example (demo)

    $tsvFile = new SplFileObject('filename.tsv');
    $tsvFile->setFlags(SplFileObject::READ_CSV);
    $tsvFile->setCsvControl("\t");
    
    $template = <<< TPL
    <data>
        <refnumber>%d</refnumber> 
        <location>%s</location>
        <name>%s</name>
        <age>%d</age>
    </data>
    TPL;
    
    $destFile = new SplFileObject('destination.xml', 'w+');
    $destFile->fwrite('<?xml version="1.0" encoding="UTF-8"?>');
    $destFile->fwrite("\n<root>\n");
    foreach ($tsvFile as $line => $row) {
        if($line > 0) {
            $destFile->fwrite(vsprintf($template, $row));
        }
    }
    $destFile->fwrite('</root>');
    

    Links

    • SplFileObject – The SplFileObject class offers an object oriented interface for a file.
    • Iterating File Contents with Spl
    • vsprintf — Return a formatted string from an array of arguments
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.