f



Create XML file from text file

Hello all!

I was wondering whether there was a way, using any XML parser
(preferably xerces), to create an XML file by reading, line by line a
text file.

Thank you,


Marios Tofarides

0
1/5/2006 10:21:17 AM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

3 Replies
815 Views

Similar Articles

[PageSpeed] 10

matofarides@gmail.com wrote:
> Hello all!
> 
> I was wondering whether there was a way, using any XML parser
> (preferably xerces), to create an XML file by reading, line by line a
> text file.

Generally not, since an XML parse, by definition, parses XML and plain 
text is not XML.  What I've done in such situations is to write a parser 
for the source language (whatever kind of language is in the text file) 
using tools like lex and yacc (and the Java equivalents) and write 
simple production rules to generate meaningful XML.  From there, you can 
use XSLT to further process the file contents, and *that* is where an 
XML parser can be useful.

Ed
0
beroset (381)
1/5/2006 11:35:18 AM
<matofarides@gmail.com> wrote in message 
news:1136456477.623890.150100@g49g2000cwa.googlegroups.com...
>
> I was wondering whether there was a way, using any XML parser
> (preferably xerces), to create an XML file by reading, line by line a
> text file.
>
Wrong tool.  You might want to have a look at 
http://servingxml.sourceforge.net/.

Regards,
Daniel Parker 


0
Daniel
1/5/2006 1:58:00 PM
matofarides@gmail.com wrote:
> Hello all!
> 
> I was wondering whether there was a way, using any XML parser
> (preferably xerces), to create an XML file by reading, line by line a
> text file.

This is called an "up-translate" and can be done with pattern-matching
software. It is possible using standard facilities like Regular
Expressions implemented in (eg Perl, Python, Tcl, etc) or even using
sed, awk, and grep, but it is much better to use a tool which knows
about XML.

Two possible tools are XSLT2 (eg as in Saxon8: saxon.sourceforge.net)
or Omnimark (www.stilo.com), both of which can be used to pattern-match
your way through plaintext data or text (and it doesn't even have to
be line-by-line either).

///Peter
-- 
XML FAQ: http://xml.silmaril.ie/
0
Peter
1/5/2006 9:13:51 PM
Reply: