• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

Converting Text File to XML

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.
  • 2
1 Solution
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.
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
fifo123Author Commented:
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?
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now