Text to XML conversion

O

Oleg

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.
 
O

Oleg

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...

Oleg said:
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 ' said:
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
 
O

Oleg

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...

Oleg said:
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 ' said:
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
 
J

Joseph Kesselman

Oleg said:
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.
 
R

roy axenov

Oleg said:
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

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.
 
P

Peter Flynn

Oleg said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top