Text to XML

  • Thread starter Mattias Thuresson
  • Start date
M

Mattias Thuresson

I want to convert a text based protocol into XML, using C#, how do I do that
in the best maner ?
Can I use XSLT in any way ? or do I have to make an parser that converts the
file manually ?

An example of the text file:
BORN ANTAL AXLAR = 220

VARMGÅNG

TJUVBROMS

TEST EFTER TÅG !!
FELKODER
W00 T02

VARMGÅNGS MÄTVÄRDEN ANTAL AXLAR = 220 TÅGRIKTNING = U
LH097 023 029 030 029 026 031 017 030 022 029 033 027 032 027 025 020 033
034 029 024 031 028 027 024 031 027 020 024 033 037 031 019 027 026 022 022
032 024 022 019 032 026 024 029 029 028 029 024 032 031 028 027 032 031 021
026 031 029 023 027 030 032 025 022 025 031 027 024 039 032 023 025 032 029
023 027 029 038 025 028 028 027 024 024 034 025 020 029 028 037 025 028 035
031 023 025 024 026 023 023 030 032 025 021 039 033 022 027 035 026 020 028
031 029 023 024 035 027 027 024 027 026 024 022 033 027 027 025 030 029 030
028 032 028 027 025 030 024 034 026 025 023 024 025 028 029 023 029 036 032
022 027 030 029 028 025 028 027 022 024 035 027 034 028 033 023 022 025 030
025 028 027 032 028 022 027 030 026 020 029 029 028 025 024 016 017 013 012
018 012 011 015 016 012 014 013 019 012 013 013 014 011 011 013 036 027 032
029 028 022 024 024 023 017 017 021 032 026 018 025 LV097 028 026 027 033
039 027 031 032 024 025 027 023 037 026 028 023 031 028 025 022 030 028 023
024 028 025 025 026 032 029 024 021 033 022 020 022 034 023 022 021 028 029
026 023 030 027 025 026 033 028 023 019 032 028 023 026 030 023 024 032 030
026 022 024 028 022 020 029 036 032 022 021 038 025 026 025 032 033 026 027
030 020 027 025 038 024 024 029 027 027 019 027 035 021 025 023 034 026 028
026 032 030 028 018 035 031 027 026 029 031 022 024 029 022 023 020 028 031
023 037 028 022 024 020 032 024 021 031 031 028 029 020 032 025 029 022 032
024 032 026 025 025 026 020 031 026 024 026 034 030 022 022 033 026 021 024
034 023 022 020 034 029 025 035 034 021 027 027 032 029 024 024 023 027 028
028 025 023 023 021 032 032 023 023 013 013 008 012 014 013 008 010 013 012
011 010 016 013 009 016 014 010 008 011 046 032 027 027 029 025 024 019 028
010 024 010 033 020 021 022

TJUVBROMS MÄTVÄRDEN
LÅGNIVÅ HS = 047
LÅGNIVÅ VS = 047
ANTAL AXLAR HS = 220
ANTAL AXLAR VS = 220 TÅGRIKTNING = U
TH 002 002 001 001 002 002 002 002 002 002 002 002 001 002 002 001 001 001
001 001 001 001 001 001 002 001 001 001 002 002 002 002 001 001 001 002 001
001 001 001 001 001 002 001 001 001 002 001 001 001 002 002 001 001 001 001
002 001 002 001 002 001 002 001 001 001 002 001 001 001 002 002 001 001 001
001 002 001 002 001 001 002 001 002 001 001 002 001 001 001 002 001 001 001
001 002 001 001 002 001 001 001 001 001 001 001 001 001 001 001 001 001 002
001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 002 001
001 001 002 001 001 001 001 002 001 001 001 001 001 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001 001 002 002 001 001 001 001 001 001
001 001 001 001 001 001 001 001 001 001 002 001 001 001 001 001 001 001 001
001 001 002 001 001 001 001 001 001 002 001 001 001 002 001 001 001 002 001
002 001 001 001 001 001 001 001 002 001 001 001 TV 001 001 002 001 002 001
003 002 002 002 003 001 003 003 002 001 001 001 003 003 001 001 001 002 003
002 001 001 001 003 003 002 001 001 002 003 002 001 001 001 002 002 002 001
001 002 003 002 001 001 001 002 002 001 001 001 003 002 001 001 002 002 002
001 001 001 003 002 001 001 002 003 001 001 001 001 003 001 001 001 003 003
002 001 002 003 002 001 001 001 002 002 001 001 003 003 001 001 002 003 001
001 001 002 002 001 002 001 002 001 001 001 003 002 001 001 002 003 001 001
001 002 002 001 001 002 003 001 001 001 003 002 001 001 003 003 001 001 002
003 001 001 002 002 001 001 002 003 001 001 002 002 001 001 002 003 001 001
001 003 002 001 002 002 002 001 001 002 002 001 001 001 002 001 002 001 002
001 001 001 002 001 001 001 002 002 002 002 002 001 002 003 001 001 002 003
001 001 002 002 001 001 002 002 001 001 003 002 001 002 002 002 001 001 002
001 002 002 001 001 <.
..
 
R

Ravikanth[MVP]

Hi

TO the best of my knowledge, there is no direct parser
avaialble to convert text to xml. You have to write a
parser which reads input text and then parse and then
create a XML.

Ravikanth[MVP]
 
G

Gustaf Liljegren

Mattias Thuresson said:
Can I use XSLT in any way ?

Only with extension functions. By default, XSLT only accepts XML input.
or do I have to make an parser that converts the file manually ?

Yes. Prepare yourself by doing an example document in XML. And unless you
need to work in Dotnet, I'd recommend a language with (even) better string
handling for this task. Python is a good alternative.

Gustaf
 

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

Top