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

  • Thread starter Raghavendra Mahuli
  • Start date
R

Raghavendra Mahuli

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
 
?

=?ISO-8859-1?Q?J=FCrgen_Kahrs?=

Raghavendra said:
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.
 
S

shaun

Raghavendra Mahuli said:
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
 

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
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top