473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Text to XML conversion

I was wondering if anyone could possibly recommend to me a tool that
would take .txt file and convert it to XML format. Thank you very much
in advance!

Oleg.

May 25 '07 #1
6 2715

Oleg wrote:
I was wondering if anyone could possibly recommend to me a
tool that would take .txt file and convert it to XML
format. Thank you very much in advance!
There's a wonderful tool called 'echo'. Used in tandem with
its trusty sidekick, 'cat', it can convert your text files
to XML in no time at all:
cat text.txt
And enterprises of great pith and moment,
With this regard, their currents turn awry,
And lose the name of action.
echo '<text><\![CDATA[' `cat text.txt` ']]></text>' >
text.xml
xmllint text.xml
<?xml version="1.0"?>
<text><![CDATA[ And enterprises of great pith and moment,
With this regard, their currents turn awry, And lose the
name of action. ]]></text>
>
Seriously though, presuming you text file contains some sort
of structured data, you shouldn't expect a canned tool to
magically divine that structure and convert it to
appropriate XML constructs (especially since 'appropriate'
is rather subjective in this case).

Oh, and XML is not a format per se. In case you meant one of
the (many) XML formats for representing structured
texts--such as DocBook--you should've said so.

--
roy axenov

If only we smelled each other's asses, there wouldn't be any
war.--Dustin Hoffman
May 25 '07 #2
Thank you very much for your answer. I didn't realize there were
different XML formats out there... The text file will be somewhat
structured. It will contains entries, each on a separate line. We need
to convert it into an XML format, so the entries can be read into a
database for one of our proprietary tools...

On May 25, 3:53 pm, roy axenov <r_axe...@mail.ruwrote:
Oleg wrote:
I was wondering if anyone could possibly recommend to me a
tool that would take .txt file and convert it to XML
format. Thank you very much in advance!

There's a wonderful tool called 'echo'. Used in tandem with
its trusty sidekick, 'cat', it can convert your text files
to XML in no time at all:
cat text.txt

And enterprises of great pith and moment,
With this regard, their currents turn awry,
And lose the name of action.echo '<text><\![CDATA[' `cat text.txt` ']]></text>' >
text.xml
xmllint text.xml

<?xml version="1.0"?>
<text><![CDATA[ And enterprises of great pith and moment,
With this regard, their currents turn awry, And lose the
name of action. ]]></text>

Seriously though, presuming you text file contains some sort
of structured data, you shouldn't expect a canned tool to
magically divine that structure and convert it to
appropriate XML constructs (especially since 'appropriate'
is rather subjective in this case).

Oh, and XML is not a format per se. In case you meant one of
the (many) XML formats for representing structured
texts--such as DocBook--you should've said so.

--
roy axenov

If only we smelled each other's asses, there wouldn't be any
war.--Dustin Hoffman

May 25 '07 #3
Thank you very much for your answer. I didn't realize there were
different XML formats out there... The text file will be somewhat
structured. It will contains entries, each on a separate line. We need
to convert it into an XML format, so the entries can be read into a
database for one of our proprietary tools...

On May 25, 3:53 pm, roy axenov <r_axe...@mail.ruwrote:
Oleg wrote:
I was wondering if anyone could possibly recommend to me a
tool that would take .txt file and convert it to XML
format. Thank you very much in advance!

There's a wonderful tool called 'echo'. Used in tandem with
its trusty sidekick, 'cat', it can convert your text files
to XML in no time at all:
cat text.txt

And enterprises of great pith and moment,
With this regard, their currents turn awry,
And lose the name of action.echo '<text><\![CDATA[' `cat text.txt` ']]></text>' >
text.xml
xmllint text.xml

<?xml version="1.0"?>
<text><![CDATA[ And enterprises of great pith and moment,
With this regard, their currents turn awry, And lose the
name of action. ]]></text>

Seriously though, presuming you text file contains some sort
of structured data, you shouldn't expect a canned tool to
magically divine that structure and convert it to
appropriate XML constructs (especially since 'appropriate'
is rather subjective in this case).

Oh, and XML is not a format per se. In case you meant one of
the (many) XML formats for representing structured
texts--such as DocBook--you should've said so.

--
roy axenov

If only we smelled each other's asses, there wouldn't be any
war.--Dustin Hoffman

May 25 '07 #4
Oleg wrote:
Thank you very much for your answer. I didn't realize there were
different XML formats out there...
XML is essentially pure syntax. To use XML, you define an XML-based
language/structure that describes the data.

So the question is which markup you want to generate. Which in your case
means understanding what text you're starting from, what wants to go
into the database so your tools can access it, and what intermediate
representation makes that easiest. Without first considering those, it's
hard to recommend tools.

If all you want to do is turn lines into records... you should be able
to import that into your database directly, without having to go through
XML.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
May 25 '07 #5
Oleg wrote:
Thank you very much for your answer. I didn't realize there were
different XML formats out there...
http://xml.silmaril.ie/basics/whatisxml/
The text file will be somewhat structured. It will contains entries,
each on a separate line. We need to convert it into an XML format, so
the entries can be read into a database for one of our proprietary
tools...
Without knowing what this XML format is, the question is impossible to
answer.

But generically, if you have a file of lines, a trivial awk or sed
script can enclose each one in markup, and add a root element to enclose
the whole thing, eg (in awk)

cat file.txt | awk 'BEGIN {print "<stuff>"} {print "<entry>" $0
"</entry>"} END {print "</stuff>"}' >file.xml

///Peter
--
XML FAQ: http://xml.silmaril.ie/
May 30 '07 #6
Oleg wrote:
I was wondering if anyone could possibly recommend to me a tool that
would take .txt file and convert it to XML format. Thank you very much
in advance!
Taking a wild guess as to what your really want to do ...
http://www.methods.co.nz/asciidoc/
Jun 14 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rare Book School | last post by:
RARE BOOK SCHOOL 2005 Rare Book School is pleased to announce its schedule of courses for 2005, including sessions at the University of Virginia, the Walters Art Museum/Johns Hopkins University...
40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
10
by: st4 | last post by:
Help, As part of my family history web site i need to get 150 pages of typed text into some format to display. It just text right now but I would like to add some graphics (photos) and make the...
5
by: Lenard Gunda | last post by:
hi! I have the following problem. I need to read data from a TXT file our company receives. I would use StreamReader, and process it line by line using ReadLine, however, the following problem...
10
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
3
by: Francesc | last post by:
Hi, I'm new at this newsgroup and I want do ask some questions and opinions about this subject. I'm developing an application focused in a very specific task: clean and labelling text documents...
4
by: George | last post by:
Hi, I am puzzled by the following and seeking some assistance to help me understand what happened. I have very limited encoding knowledge. Our SAP system writes out a text file which includes...
2
by: kinarism | last post by:
Sorry for posting on multiple groups with this, I am new to the groups and didnt know the possibility of "cross-posting" was possible. Anyway, my post in the "upgrade" group hasnt gotten any...
2
by: sethridge1991 | last post by:
Hi Everyone, I am trying to send a XML file via SFTP staying completely in UNIX. The data in the file will vary everytime I create and send it. This is not a simple address book dump. This...
6
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.