convert text to xml

N

neeraja.ram

Hello All,

I am just learning XML. I need your help in converting a text file to
XML. The text file is not a delimited one for me to do the things
easily.

for eg. a sample file could be like...

First Name : abcd
Last Name : xyz
Content : This is a sample text. It can contain
- Anything
- something
- Nothing
Start Time : 12/08/2006 14:50

The XML should be like

<Root>
<FirstName>abcd</FirstName>
<LastName>xyz</LastName>
<Content>This is a sample text. It can contain
- Anything
- something
- Nothing
</Content>
<STime>12/08/2006 14:50</STime>
</Root>

And with this XML, i need to use XSL to display the contents in a table
(HTML Format). Except the other elements, i find difficult to parse the
"Content" as i need to display as it is. When i use <value-of
select="Content">, i get the contents in a single line but i need to
display it as it is in multiple lines

Thanks in advance for your help.

Regards,
Neeraja
 
A

Andy Dingley

I need your help in converting a text file to
XML. The text file is not a delimited one for me to do the things
easily.

Easiest option is to re-write the file generator so that it makes the
output in XML.

If you can't do that, then set your time machien for 10 years ago and
do it with Perl (or Python), as we used to back then. There's nothing
useful that XML or XSLT can offer to you here - you need to get it into
XML before the tools even begin to be usable.
 
P

Peter Flynn

Hello All,

I am just learning XML. I need your help in converting a text file to
XML. The text file is not a delimited one for me to do the things
easily.

for eg. a sample file could be like...

First Name : abcd
Last Name : xyz
Content : This is a sample text. It can contain
- Anything
- something
- Nothing
Start Time : 12/08/2006 14:50

The most common approach is to use one of the standard scripting
languages like awk, perl, python, tcl, etc to write a program to
pattern-match what you want to extract and output it with the
relevant tags around it.

Two other solutions are Omnimark (a pattern-matching language
designed for use with XML) and XSLT2, which has the ability to
read plaintext files.
The XML should be like

<Root>
<FirstName>abcd</FirstName>
<LastName>xyz</LastName>
<Content>This is a sample text. It can contain
- Anything
- something
- Nothing
</Content>
<STime>12/08/2006 14:50</STime>
</Root>

And with this XML, i need to use XSL to display the contents in a table
(HTML Format). Except the other elements, i find difficult to parse the
"Content" as i need to display as it is. When i use <value-of
select="Content">, i get the contents in a single line but i need to
display it as it is in multiple lines

value-of should output the content as-is. Check your processor
settings for the handling of line-ends and space suppression.

///Peter
 

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
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top