Text to XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mattias Thuresson

    #1

    Text to XML

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


  • Ravikanth[MVP]

    #2
    Text to XML

    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]

    [color=blue]
    >-----Original Message-----
    >I want to convert a text based protocol into XML, using [/color]
    C#, how do I do that[color=blue]
    >in the best maner ?
    >Can I use XSLT in any way ? or do I have to make an [/color]
    parser that converts the[color=blue]
    >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 [/color]
    032 027 025 020 033[color=blue]
    >034 029 024 031 028 027 024 031 027 020 024 033 037 031 [/color]
    019 027 026 022 022[color=blue]
    >032 024 022 019 032 026 024 029 029 028 029 024 032 031 [/color]
    028 027 032 031 021[color=blue]
    >026 031 029 023 027 030 032 025 022 025 031 027 024 039 [/color]
    032 023 025 032 029[color=blue]
    >023 027 029 038 025 028 028 027 024 024 034 025 020 029 [/color]
    028 037 025 028 035[color=blue]
    >031 023 025 024 026 023 023 030 032 025 021 039 033 022 [/color]
    027 035 026 020 028[color=blue]
    >031 029 023 024 035 027 027 024 027 026 024 022 033 027 [/color]
    027 025 030 029 030[color=blue]
    >028 032 028 027 025 030 024 034 026 025 023 024 025 028 [/color]
    029 023 029 036 032[color=blue]
    >022 027 030 029 028 025 028 027 022 024 035 027 034 028 [/color]
    033 023 022 025 030[color=blue]
    >025 028 027 032 028 022 027 030 026 020 029 029 028 025 [/color]
    024 016 017 013 012[color=blue]
    >018 012 011 015 016 012 014 013 019 012 013 013 014 011 [/color]
    011 013 036 027 032[color=blue]
    >029 028 022 024 024 023 017 017 021 032 026 018 025 [/color]
    LV097 028 026 027 033[color=blue]
    >039 027 031 032 024 025 027 023 037 026 028 023 031 028 [/color]
    025 022 030 028 023[color=blue]
    >024 028 025 025 026 032 029 024 021 033 022 020 022 034 [/color]
    023 022 021 028 029[color=blue]
    >026 023 030 027 025 026 033 028 023 019 032 028 023 026 [/color]
    030 023 024 032 030[color=blue]
    >026 022 024 028 022 020 029 036 032 022 021 038 025 026 [/color]
    025 032 033 026 027[color=blue]
    >030 020 027 025 038 024 024 029 027 027 019 027 035 021 [/color]
    025 023 034 026 028[color=blue]
    >026 032 030 028 018 035 031 027 026 029 031 022 024 029 [/color]
    022 023 020 028 031[color=blue]
    >023 037 028 022 024 020 032 024 021 031 031 028 029 020 [/color]
    032 025 029 022 032[color=blue]
    >024 032 026 025 025 026 020 031 026 024 026 034 030 022 [/color]
    022 033 026 021 024[color=blue]
    >034 023 022 020 034 029 025 035 034 021 027 027 032 029 [/color]
    024 024 023 027 028[color=blue]
    >028 025 023 023 021 032 032 023 023 013 013 008 012 014 [/color]
    013 008 010 013 012[color=blue]
    >011 010 016 013 009 016 014 010 008 011 046 032 027 027 [/color]
    029 025 024 019 028[color=blue]
    >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 [/color]
    002 002 001 001 001[color=blue]
    >001 001 001 001 001 001 002 001 001 001 002 002 002 002 [/color]
    001 001 001 002 001[color=blue]
    >001 001 001 001 001 002 001 001 001 002 001 001 001 002 [/color]
    002 001 001 001 001[color=blue]
    >002 001 002 001 002 001 002 001 001 001 002 001 001 001 [/color]
    002 002 001 001 001[color=blue]
    >001 002 001 002 001 001 002 001 002 001 001 002 001 001 [/color]
    001 002 001 001 001[color=blue]
    >001 002 001 001 002 001 001 001 001 001 001 001 001 001 [/color]
    001 001 001 001 002[color=blue]
    >001 001 001 001 001 001 001 001 001 001 001 001 001 001 [/color]
    001 001 001 002 001[color=blue]
    >001 001 002 001 001 001 001 002 001 001 001 001 001 001 [/color]
    001 001 001 001 001[color=blue]
    >001 001 001 001 001 001 001 001 001 001 001 002 002 001 [/color]
    001 001 001 001 001[color=blue]
    >001 001 001 001 001 001 001 001 001 001 002 001 001 001 [/color]
    001 001 001 001 001[color=blue]
    >001 001 002 001 001 001 001 001 001 002 001 001 001 002 [/color]
    001 001 001 002 001[color=blue]
    >002 001 001 001 001 001 001 001 002 001 001 001 TV 001 [/color]
    001 002 001 002 001[color=blue]
    >003 002 002 002 003 001 003 003 002 001 001 001 003 003 [/color]
    001 001 001 002 003[color=blue]
    >002 001 001 001 003 003 002 001 001 002 003 002 001 001 [/color]
    001 002 002 002 001[color=blue]
    >001 002 003 002 001 001 001 002 002 001 001 001 003 002 [/color]
    001 001 002 002 002[color=blue]
    >001 001 001 003 002 001 001 002 003 001 001 001 001 003 [/color]
    001 001 001 003 003[color=blue]
    >002 001 002 003 002 001 001 001 002 002 001 001 003 003 [/color]
    001 001 002 003 001[color=blue]
    >001 001 002 002 001 002 001 002 001 001 001 003 002 001 [/color]
    001 002 003 001 001[color=blue]
    >001 002 002 001 001 002 003 001 001 001 003 002 001 001 [/color]
    003 003 001 001 002[color=blue]
    >003 001 001 002 002 001 001 002 003 001 001 002 002 001 [/color]
    001 002 003 001 001[color=blue]
    >001 003 002 001 002 002 002 001 001 002 002 001 001 001 [/color]
    002 001 002 001 002[color=blue]
    >001 001 001 002 001 001 001 002 002 002 002 002 001 002 [/color]
    003 001 001 002 003[color=blue]
    >001 001 002 002 001 001 002 002 001 001 003 002 001 002 [/color]
    002 002 001 001 002[color=blue]
    >001 002 002 001 001 <.
    >..
    >
    >
    >.
    >[/color]

    Comment

    • Gustaf Liljegren

      #3
      Re: Text to XML

      "Mattias Thuresson" <mth@home.se> wrote:
      [color=blue]
      > Can I use XSLT in any way ?[/color]

      Only with extension functions. By default, XSLT only accepts XML input.
      [color=blue]
      > or do I have to make an parser that converts the file manually ?[/color]

      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

      Comment

      Working...