Text to XML conversion

Discussion in 'XML' started by Oleg, May 25, 2007.

  1. Oleg

    Oleg Guest

    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.
     
    Oleg, May 25, 2007
    #1
    1. Advertising

  2. Oleg

    Oleg Guest

    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 <> wrote:
    > 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
     
    Oleg, May 25, 2007
    #2
    1. Advertising

  3. Oleg

    Oleg Guest

    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 <> wrote:
    > 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
     
    Oleg, May 25, 2007
    #3
  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
     
    Joseph Kesselman, May 25, 2007
    #4
  5. Oleg

    roy axenov Guest

    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
     
    roy axenov, May 25, 2007
    #5
  6. Oleg

    Peter Flynn Guest

    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/
     
    Peter Flynn, May 31, 2007
    #6
  7. Oleg

    Ian Wilson Guest

    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/
     
    Ian Wilson, Jun 14, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raghavendra Mahuli
    Replies:
    2
    Views:
    397
    shaun
    Nov 3, 2005
  2. Francesc
    Replies:
    3
    Views:
    560
  3. Peter Flynn
    Replies:
    3
    Views:
    472
  4. =?iso-8859-1?q?Benjamin_B=E9car?=

    XML <=> Text conversion platform requiring high performance

    =?iso-8859-1?q?Benjamin_B=E9car?=, Aug 24, 2006, in forum: XML
    Replies:
    8
    Views:
    350
    =?iso-8859-1?q?Benjamin_B=E9car?=
    Aug 25, 2006
  5. Replies:
    2
    Views:
    490
    Peter Flynn
    Jun 22, 2007
Loading...

Share This Page