conversion from one *format in a text file* -> to xml

Discussion in 'XML' started by Raghavendra Mahuli, Nov 3, 2005.

  1. Hello,

    I have a text file in which records are stored in a particular format. For
    ex:

    Node1( att1, att2, node2(attx))

    I need to convert it to xml. I know xsl can be used to convert *xml to* some
    other format. But i need the reverse operation.
    Same thing in xml has to be transformed to something like(need not be
    exactly):

    <n name="Node1">
    <a> att1</a>
    <a> att2</a>
    <n name="node2">
    <a>attx</a>
    </n>
    </n>



    Can u pls give me some pointers to convert a predefined format to xml.


    thanks in advance.
    warm regards
     
    Raghavendra Mahuli, Nov 3, 2005
    #1
    1. Advertising

  2. Raghavendra Mahuli wrote:

    > I have a text file in which records are stored in a particular format. For
    > ex:
    >
    > Node1( att1, att2, node2(attx))


    This looks like the parameters like node2 may be
    deeply nested. In this case, you really need a
    parser for your own data format. This is not as
    trivial as converting simple tables to XML.

    You probably need something like lex and yacc in
    this case. As an alternative, I have used awk for
    implementing such a parser.
     
    =?ISO-8859-1?Q?J=FCrgen_Kahrs?=, Nov 3, 2005
    #2
    1. Advertising

  3. Raghavendra Mahuli

    shaun Guest

    In article <dkcirv$8l5$>,
    "Raghavendra Mahuli" <> wrote:

    >Hello,
    >
    >I have a text file in which records are stored in a particular format. For
    >ex:
    >
    >Node1( att1, att2, node2(attx))
    >
    >I need to convert it to xml. I know xsl can be used to convert *xml to* some
    >other format. But i need the reverse operation.
    >Same thing in xml has to be transformed to something like(need not be
    >exactly):
    >
    ><n name="Node1">
    > <a> att1</a>
    > <a> att2</a>
    > <n name="node2">
    > <a>attx</a>
    > </n>
    ></n>


    Take a look at :
    http://www.idealliance.org/proceedings/xml04/papers/111/mhk-paper.html#S2
    ..
    if you have access to XSLT 2.0 (e.g. via Michael Kays saxon 8.x.x) then
    you can 'upconvert' plaintext to xml using an xslt. I had a similar
    task, but i have to admit I ended up using a lot of "tokenize" followed
    by "for-each" structures rather than the "analyze-string" as advocated
    in the article. My regex wasn't up to scratch, probably.
    cheers
    shaun
     
    shaun, Nov 3, 2005
    #3
    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.

Share This Page