Converting Text File to XML

Posted on 2005-03-29
Medium Priority
Last Modified: 2013-11-19
I have a client application that can either send a text file or an xml file.  If it is a text file, I want to convert it into an XML file that I want based on a schema file.  If it is an xml file, I want to make sure the xml file conforms to the schema.  I believe the best way to approach this task is to create some type of component that's able to take in a text file and xml file and produce a final xml file.  I’m writing the application in C# but I’m novice to XML.  Any help would be appreciated.
Question by:fifo123
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 15

Expert Comment

ID: 13660394
hm...in general it all depends on your text file format.

you should write parser for this format (or take exist one), and then just parse the file -> get data-> store it as XML.
LVL 22

Expert Comment

ID: 13670028
DualSoul is right, you will need a parser to convert this text file to XML, and this means you will need to create a standard format for your text file, that all text files will adhere to, if you don't the parser will not be able to convert the text file, as it will not understand it.

I don't know what sort of data you are handling but this is an example of how to format your text files, keep in mind this is just one way, I am line delimiting, but you could delimit or mark your sections using many other methods

----------------->start example text file format
John Smith             --> line 1, always customer name
123 Abc street        --> line 2, customer address line 1
NormalVille             --> line 3, customer address line 2
----------------->end example text file format

this could be converted to the following xml

<?xml version="1.0"?>
    <name val="John Smith" />
    <address_line1 val="123 Abc Street" />
    <address_line2 val="Normalville" />

Hope this helps

Author Comment

ID: 13672907
That definitely helps.  I have another scenario that I’m looking to tackle also.
I have several clients that post xml messages to my application.  I have no control over the format of the xml messages they post.  What I want to do is take their xml message and produce another xml message based on a schema that I have.  I am thinking I need to use XSL to accomplish that; basically transform one xml document to another based on a schema.  Is there another solution I should consider for this?
LVL 22

Accepted Solution

RedKelvin earned 150 total points
ID: 13677139
No I cannot think of another solution to do the transformation, unless you just read the file look for tags and do it all manually in code.

If you can do it with XSL that would be your best option.


Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question