Loading ...
Sorry, an error occurred while loading the content.

txt to xml

Expand Messages
  • michaelcbramley
    I would like to convert a simple text file to an xml file. delimited with my choice from the usual suspects. Can someone nudge me in the right direction?
    Message 1 of 8 , Apr 9 9:26 AM
    View Source
    • 0 Attachment
      I would like to convert a simple text file to an xml file. delimited
      with my choice from the usual suspects. Can someone nudge me in the
      right direction? Thanks

      smething like


      apples,applesitemcode,applesbarcode1,applesbarcode2
      oranges,orangesitemcode,orangesbarcode1,orangesbarcode2

      <fruitbowl>
      <fruit>
      <fruitname>apples</fruitname>
      <fruititemcode>applesitemcode</fruititemcode>
      <fruitbarcode1>applesbarcode1</fruitbarcode1>
      <fruitbarcode2>applesbarcode2</fruitbarcode2>
      </fruit>
      <fruit>
      <fruitname>oranges<\fruitname>
      <fruititemcode>orangesitemcode</fruititemcode>
      <fruitbarcode1>orangesbarcode1</fruitbarcode1>
      <fruitbarcode2>orangesbarcode2</fruitbarcode2>
      </fruit>
      </fruitbowl>
    • loro
      ... I ll give it a go. Each line is basically an array, so let s use that. The below clip assumes the fruit lists are all there is in the document and that
      Message 2 of 8 , Apr 13 10:32 AM
      View Source
      • 0 Attachment
        michaelcbramley wrote:
        >I would like to convert a simple text file to an xml file. delimited
        >with my choice from the usual suspects. Can someone nudge me in the
        >right direction? Thanks
        >
        >smething like
        >
        >
        >apples,applesitemcode,applesbarcode1,applesbarcode2
        >oranges,orangesitemcode,orangesbarcode1,orangesbarcode2
        >
        ><fruitbowl>
        ><fruit>
        ><fruitname>apples</fruitname>
        ><fruititemcode>applesitemcode</fruititemcode>
        ><fruitbarcode1>applesbarcode1</fruitbarcode1>
        ><fruitbarcode2>applesbarcode2</fruitbarcode2>
        ></fruit>
        ><fruit>
        ><fruitname>oranges<\fruitname>
        ><fruititemcode>orangesitemcode</fruititemcode>
        ><fruitbarcode1>orangesbarcode1</fruitbarcode1>
        ><fruitbarcode2>orangesbarcode2</fruitbarcode2>
        ></fruit>
        ></fruitbowl>

        I'll give it a go. Each line is basically an array, so let's use
        that. The below clip assumes the fruit lists are all there is in the
        document and that there are no blank lines at the bottom either. It
        jumps to the start of the doc and chews line by line until there are
        no more, then it writes out the XML in a new document. I didn't test
        it much, so FWIW...

        Oh, at least one long line will wrap in email so you have to unwrap
        it. I marked the spots with comments.

        _________________________________________

        h=fruitXML

        ^!SetWordWrap off
        ^!SetPasteIndent off
        ^!SetListDelimiter ,
        ^!Jump text_start

        ^!Set %cntr%=0
        :loop
        ^!Inc %cntr%
        ; Get each line into an array
        ^!SetArray %^%cntr%_item%=^$GetLine$
        ; Change each array item to include XML tags
        ; Each ^!Set comman should be on a single line (email may wrap them),
        ^!Set %^%cntr%_item1%=<fruitname>^%^%cntr%_item1%</fruitname>
        ^!Set %^%cntr%_item2%=<fruititemcode>^%^%cntr%_item2%</fruititemcode>
        ^!Set %^%cntr%_item3%=<fruitbarcode1>^%^%cntr%_item3%</fruitbarcode1>
        ^!Set %^%cntr%_item4%=<fruitbarcode2>^%^%cntr%_item4%</fruitbarcode2>
        ; Kill loop at the last line
        ^!If ^$GetRow$ = ^$GetLineCount$ xmldoc
        ^!Jump +1
        ^!Goto loop

        :xmldoc
        ^!Menu File/New
        ^!Set %cntr2%=0
        :loop2
        ^!Inc %cntr2%
        ; Print it out
        ; Long line follows. Email will wrap it.
        ^!InsertText
        <fruit>^p^%space%^%space%^%^%cntr2%_item1%^p^%space%^%space%^%^%cntr2%_item2%^p^%space%^%space%^%^%cntr2%_item3%^p^%space%^%space%^%^%cntr2%_item4%^p</fruit>^p
        ; End of long line
        ; Kill loop whan there are no more lines to print
        ^!If ^%cntr2%=^%cntr% end else loop2
        _________________________________________


        Lotta
      • loro
        Ack, I forgot the fruitbowl! The long line is now even longer. :-) ... fruitXML ^!SetWordWrap off ^!SetPasteIndent off ^!SetListDelimiter , ^!Jump text_start
        Message 3 of 8 , Apr 13 10:53 AM
        View Source
        • 0 Attachment
          Ack, I forgot the fruitbowl! The long line is now even longer. :-)

          ---------------------------------------------------------
          fruitXML

          ^!SetWordWrap off
          ^!SetPasteIndent off
          ^!SetListDelimiter ,
          ^!Jump text_start

          ^!Set %cntr%=0
          :loop
          ^!Inc %cntr%
          ; Get each line into an array
          ^!SetArray %^%cntr%_item%=^$GetLine$
          ; Change each array item to include XML tags
          ; Each ^!Set comman should be on a single line (email may wrap them),
          ^!Set %^%cntr%_item1%=<fruitname>^%^%cntr%_item1%</fruitname>
          ^!Set %^%cntr%_item2%=<fruititemcode>^%^%cntr%_item2%</fruititemcode>
          ^!Set %^%cntr%_item3%=<fruitbarcode1>^%^%cntr%_item3%</fruitbarcode1>
          ^!Set %^%cntr%_item4%=<fruitbarcode2>^%^%cntr%_item4%</fruitbarcode2>
          ; Kill loop at the last line
          ^!If ^$GetRow$ = ^$GetLineCount$ xmldoc
          ^!Jump +1
          ^!Goto loop

          :xmldoc
          ^!Menu File/New
          ^!Inserttext <fruitbowl>^p
          ^!Set %cntr2%=0
          :loop2
          ^!Inc %cntr2%
          ; Print it out
          ; Long line follows. Email will wrap it.
          ^!InsertText
          ^%space%^%space%<fruit>^p^%space%^%space%^%space%^%space%^%^%cntr2%_item1%^p^%space%^%space%^%space%^%space%^%^%cntr2%_item2%^p^%space%^%space%^%space%^%space%^%^%cntr2%_item3%^p^%space%^%space%^%space%^%space%^%^%cntr2%_item4%^p^%space%^%space%</fruit>^p
          ; End of long ine
          ; Kill loop when there are no more lines to format
          ^!If ^%cntr2%=^%cntr% finish else loop2

          :finish
          ^!InsertText </fruitbowl>
          ---------------------------------------------------------

          Lotta
        • Michael Bramley
          Ack true. lot of love lotta. Currently in a bar so unable to decipher but thanks for your advice.
          Message 4 of 8 , Apr 13 11:43 AM
          View Source
          • 0 Attachment
            Ack true. lot of love lotta. Currently in a bar so unable to decipher
            but <many> thanks for your advice.

            On 13/04/2008, loro <loro-spam01-@...> wrote:
            > Ack, I forgot the fruitbowl! The long line is now even longer. :-)
            >
            > ---------------------------------------------------------
            > fruitXML
            >
            > ^!SetWordWrap off
            > ^!SetPasteIndent off
            > ^!SetListDelimiter ,
            > ^!Jump text_start
            >
            > ^!Set %cntr%=0
            > :loop
            > ^!Inc %cntr%
            > ; Get each line into an array
            > ^!SetArray %^%cntr%_item%=^$GetLine$
            > ; Change each array item to include XML tags
            > ; Each ^!Set comman should be on a single line (email may wrap them),
            > ^!Set %^%cntr%_item1%=<fruitname>^%^%cntr%_item1%</fruitname>
            > ^!Set %^%cntr%_item2%=<fruititemcode>^%^%cntr%_item2%</fruititemcode>
            > ^!Set %^%cntr%_item3%=<fruitbarcode1>^%^%cntr%_item3%</fruitbarcode1>
            > ^!Set %^%cntr%_item4%=<fruitbarcode2>^%^%cntr%_item4%</fruitbarcode2>
            > ; Kill loop at the last line
            > ^!If ^$GetRow$ = ^$GetLineCount$ xmldoc
            > ^!Jump +1
            > ^!Goto loop
            >
            > :xmldoc
            > ^!Menu File/New
            > ^!Inserttext <fruitbowl>^p
            > ^!Set %cntr2%=0
            > :loop2
            > ^!Inc %cntr2%
            > ; Print it out
            > ; Long line follows. Email will wrap it.
            > ^!InsertText
            > ^%space%^%space%<fruit>^p^%space%^%space%^%space%^%space%^%^%cntr2%_item1%^p^%space%^%space%^%space%^%space%^%^%cntr2%_item2%^p^%space%^%space%^%space%^%space%^%^%cntr2%_item3%^p^%space%^%space%^%space%^%space%^%^%cntr2%_item4%^p^%space%^%space%</fruit>^p
            > ; End of long ine
            > ; Kill loop when there are no more lines to format
            > ^!If ^%cntr2%=^%cntr% finish else loop2
            >
            > :finish
            > ^!InsertText </fruitbowl>
            > ---------------------------------------------------------
            >
            > Lotta
            >
            >
          • loro
            I m sorry. I shouldn t be allowed to use an email program. The first line should of course be h= fruitXML NOT fruitXML Sigh. Lotta
            Message 5 of 8 , Apr 13 1:16 PM
            View Source
            • 0 Attachment
              I'm sorry. I shouldn't be allowed to use an email program.

              The first line should of course be

              h="fruitXML"

              NOT

              fruitXML


              Sigh.
              Lotta
            • dracorat
              I have a similar clip if you d like to see it. It s no better than the one posted I think, but it s good for the purposes of analysis if anyone would like to
              Message 6 of 8 , Apr 14 10:57 AM
              View Source
              • 0 Attachment
                I have a similar clip if you'd like to see it. It's no better than the
                one posted I think, but it's good for the purposes of analysis if
                anyone would like to read over them for education. Let me know and
                I'll post it.

                The biggest changes I can see are that mine will show a progress
                percent (because I tend to do large files) and I don't store all the
                results then write them, I write them as I go. It's probably a bit
                slower that way, but I consume much less memory in processing.

                --Keith

                --- In ntb-clips@yahoogroups.com, loro <loro-spam01-@...> wrote:
                >
                > I'll give it a go. Each line is basically an array, so let's use
                > that. The below clip assumes the fruit lists are all there is in the
                > document and that there are no blank lines at the bottom either. It
                > jumps to the start of the doc and chews line by line until there are
                > no more, then it writes out the XML in a new document. I didn't test
                > it much, so FWIW...
                >
                > Oh, at least one long line will wrap in email so you have to unwrap
                > it. I marked the spots with comments.
                >
                > [...]
                >
                > Lotta
                >
              • Michael Bramley
                Thanks Keith and Lotta. Yes, Keith, anything that sheds a bit more light will be great. Michael
                Message 7 of 8 , Apr 14 1:12 PM
                View Source
                • 0 Attachment
                  Thanks Keith and Lotta. Yes, Keith, anything that sheds a bit more
                  light will be great. Michael

                  On 14/04/2008, dracorat <dracorat@...> wrote:
                  > I have a similar clip if you'd like to see it. It's no better than the
                  > one posted I think, but it's good for the purposes of analysis if
                  > anyone would like to read over them for education. Let me know and
                  > I'll post it.
                  >
                  > The biggest changes I can see are that mine will show a progress
                  > percent (because I tend to do large files) and I don't store all the
                  > results then write them, I write them as I go. It's probably a bit
                  > slower that way, but I consume much less memory in processing.
                  >
                  > --Keith
                  >
                  > --- In ntb-clips@yahoogroups.com, loro <loro-spam01-@...> wrote:
                  > >
                  > > I'll give it a go. Each line is basically an array, so let's use
                  > > that. The below clip assumes the fruit lists are all there is in the
                  > > document and that there are no blank lines at the bottom either. It
                  > > jumps to the start of the doc and chews line by line until there are
                  > > no more, then it writes out the XML in a new document. I didn't test
                  > > it much, so FWIW...
                  > >
                  > > Oh, at least one long line will wrap in email so you have to unwrap
                  > > it. I marked the spots with comments.
                  > >
                  > > [...]
                  > >
                  > > Lotta
                  > >
                  >
                  >
                  >
                • dracorat
                  Here you go - watch for line breaks and at the top of the file, there are two lines you should chage to whatever file you d like the clip to save to I do that
                  Message 8 of 8 , Apr 14 1:23 PM
                  View Source
                  • 0 Attachment
                    Here you go - watch for line breaks and at the top of the file, there
                    are two lines you should chage to whatever file you'd like the clip
                    to save to

                    I do that for batch automation.

                    --Keith
                    -----------------------------
                    ^!SetScreenUpdate Off
                    ^!SET %DocIndex%=^$GetDocIndex$
                    ^!SET %FName%="C:\output.xml"
                    ^!SET %Progress%=0
                    ^!SET %LastProgress%=-1
                    ^!SET %FileCheck%=^$GetFiles("c:\";output.XML)$
                    ^!SetWordWrap OFF
                    ^!If "^%FileCheck%" > "" NEXT ELSE CreateFile
                    ^!Open ^%FName% /J=-1
                    ^!SetWordWrap OFF
                    ^!Goto BeginWork
                    :CreateFile
                    ^!TOOLBAR New Document
                    ^!SetWordWrap OFF
                    ^!Save AS ^%FName%

                    :BeginWork
                    ^!SetDocIndex ^%DocIndex%
                    ^!Jump DOC_START
                    ^!Set %TotalLines%=^$GetLineCount$
                    ^!Set %CurrentLine%=0

                    :WorkLoop
                    ^!Select LINE
                    ^!SET %Progress%="^$Calc((^%CurrentLine%/^%TotalLines%)*100;1)$"
                    ^!IF ^%Progress% = ^%LastProgress% NoUpdate
                    ^!SET %LastProgress%=^%Progress%
                    ^!StatusShow "^%Progress%%"
                    :NoUpdate
                    ^!Find "([^\,]+)\,([^\,]+)\,([^\,]+)\,([^\,]+)" HRS
                    ^!SetArray %Data%=^$GetReSubStrings$
                    ^!IF ^%Data0% < 4 BADROW
                    ^!SET %Data1%=^$StrReplace("&";"&";^%Data1%;False;False)$
                    ^!SET %Data2%=^$StrReplace("&";"&";^%Data2%;False;False)$
                    ^!SET %Data3%=^$StrReplace("&";"&";^%Data3%;False;False)$
                    ^!SET %Data4%=^$StrReplace("&";"&";^%Data4%;False;False)$
                    ^!Open ^%FName% /J=-1
                    ^!InsertText
                    "<fruit><fruitname>^%Data1%</fruitname><fruititemcode>^%Data2%</fruititemcode><fruitbarcode1>^%Data3%</fruitbarcode1><fruitbarcode2>^%Data4</fruitbarcod2></fruit>^P"
                    :^!Save AS ^%FName%
                    ^!Goto PostProcessing

                    :BadRow

                    :PostProcessing
                    ^!SetDocIndex ^%DocIndex%
                    ^!Set %CurrentLine%="^$Calc(^%CurrentLine%+1)$"
                    ^!If ^%CurrentLine%=^%TotalLines% FinishOut
                    ^!Select 0
                    ^!Jump +1
                    ^!Goto WorkLoop

                    :FinishOut
                    ^!Select 0
                    ^!Jump DOC_END
                    ^!Open ^%FName% /J=-1
                    -----------------------------

                    --- In ntb-clips@yahoogroups.com, "Michael Bramley"
                    <michaelbramley@...> wrote:
                    >
                    > Thanks Keith and Lotta. Yes, Keith, anything that sheds a bit more
                    > light will be great. Michael
                    >
                  Your message has been successfully submitted and would be delivered to recipients shortly.