removing comma’s from xml file

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf removing comma’s from xml file

  • Creator
    Topic
  • #50785
    Mason Miller
    Participant

      I am trying to remove all comma’s from an xml file before I send it though translation I am converting it to .csv I have created a tps proc and I know I am doing something wrong but I just can’t figure out what here is the tps proc I created.

      # UPoC type: tps

      # Args: tps keyedlist containing the following keys:

      #       MODE    run mode (“start”, “run” or “time”)

      #       MSGID   message handle

      #       ARGS    user-supplied arguments:

      #              

      #

      # Returns: tps disposition list:

      #          

      #

      proc tps_remove_comma { args } {

         keylget args MODE mode               ;# Fetch mode

         set dispList {} ;# Nothing to return

         switch -exact — $mode {

             start {

                 # Perform special init functions

         # N.B.: there may or may not be a MSGID key in args

             }

             run {

         # ‘run’ mode always has a MSGID; fetch and process it

                 keylget args MSGID mh

      set var1 [msgget $mh]

      set mh [regsub -all “,” $var1 “”]

                 lappend dispList “CONTINUE $mh”

             }

             time {

                 # Timer-based processing

         # N.B.: there may or may not be a MSGID key in args

             }

             

             shutdown {

         # Doing some clean-up work

      }

         }

         return $dispList

      }

      If I test the TPS proc in the testing tool it removes the comma’s but when I put it in the pre-proc and test the xlate it will not work. any suggestions?

    Viewing 8 reply threads
    • Author
      Replies
      • #67508
        Charlie Bursell
        Participant

          set var1 [msgget $mh]

          set mh [regsub -all “,” $var1 “”]

          msgset $mh $var1

          lappend dispList “CONTINUE $mh”

          However if it were me, I would replace the whole run mode with something like:

          run {

             keylget args MSGID mh

             msgset $mh [string map “, {}” [msgget $mh]]

             lappend dispList “CONTINUE $mh”

          }

        • #67509
          Mason Miller
          Participant

            Thanks that worked

            One more question if I wanted to remove all newlines from the data would the string map command work if I used

            string map “n {}” [msgget $mh]

          • #67510
            Charlie Bursell
            Participant

              Yes

            • #67511
              Mason Miller
              Participant

                I am having trouble removing the newlines I am getting an error in the testing tool that says

                msgId = message0

                proc = ‘tps_remove_newline’

                args = ”

                result = ‘char map list unbalanced’

                errorInfo: ‘

                char map list unbalanced

                   while executing

                “string map “n {}” [msgget $mh]”

                   (“run” arm line 3)

                   invoked from within

                “switch -exact — $mode {

                       start {

                           # Perform special init functions

                   # N.B.: there may or may not be a MSGID key in args

                      …”

                   (procedure “tps_remove_newline” line 6)

                   invoked from within

                “tps_remove_newline {MSGID message0} {CONTEXT sms_ib_data} {ARGS {}} {MODE run} {VERSION 3.0}”‘

              • #67512
                Tom Rioux
                Participant

                  Mason,

                  Try this:   string map “\n {}” [msgget $mh]

                  This should work for you.   Depending on what you want to do however, this may end up concating the previous line with the following line.   If that isn’t the desired result and you want to retain a space, then simply just modify as such, putting a space between the curly braces:

                  string map “\n { }” [msgget $mh]

                  Hope this helps…

                  Tom

                • #67513
                  Charlie Bursell
                  Participant

                    You guys make it too complicated.  ðŸ˜€

                     

                    Tcl trys to evaluate between double quotes

                    ethier this

                    set msg [string map {n “”} [msgget $mh]]

                    or, even better since the map is a list:

                    set msg [string map

                      [msgget $mh]]

                  • #67514
                    Ayan George
                    Participant

                      Charlie Bursell wrote:

                      You guys make it too complicated.

                    • #67515
                      Charlie Bursell
                      Participant

                        Because if you get in the habit of using the list command to build a list it will keep you out of trouble.  The list command will provide the proper quoting if there are spaces, etc.  It is the old 5% rule.  It will only bite you 5% ofthe time butthem you will spend 90% of your time trying to find the problem.

                        If you are happy with your list so am I. 😀

                      • #67516
                        Mason Miller
                        Participant

                          Thanks it is working now.

                      Viewing 8 reply threads
                      • The forum ‘Cloverleaf’ is closed to new topics and replies.