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

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

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

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. loveNUNO
    Replies:
    2
    Views:
    1,209
    loveNUNO
    Nov 20, 2003
  2. john schultz
    Replies:
    2
    Views:
    595
    Victor Porton
    Jun 5, 2004
  3. sachin
    Replies:
    1
    Views:
    489
    Tjerk Wolterink
    Dec 1, 2005
  4. jkflens
    Replies:
    2
    Views:
    1,738
    jkflens
    May 30, 2006
  5. Johan
    Replies:
    20
    Views:
    1,961
    Arndt Jonasson
    Feb 27, 2007
  6. Randy Kramer
    Replies:
    2
    Views:
    608
    Randy Kramer
    Jan 12, 2007
  7. Erik Wasser
    Replies:
    5
    Views:
    849
    Peter J. Holzer
    Mar 5, 2006
  8. Wesley
    Replies:
    1
    Views:
    503
    Wesley
    Apr 15, 2014
Loading...