ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Image in XML

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Image in XML

    Hey Guys,

    Can anyone of you help in one question regarding XML.

    How can I send image in XML, what would be the encoding I would use to send.

    How can I parse the image in my RPG program through SAX or DOM API's.

    if anyone can give me some example that would be really helpful for me.

    Thanks,
    Mini

  • #2
    Re: Image in XML

    Hello

    MIME:Base64 is the standard for encoding non XML data in an XML file. Be sure to decode it in the same character set you used to encode it, otherwise you will break it.

    Here is a program I wrote a while ago to do the encoding, please excuse the use of numeric indicators (I know it's bad, but I couldn't find a better way):

    Code:
         H Debug
         H DatEdit(*Ymd/)
         H Option(*NoDebugIO)
         H Aut(*All)
         ?*  Fields
         DString           S            150
         DStringOut        S            200
         DEndChar          S              3  0
         DChar             S              1
         DIx               S              1  0
         DJx               S              3  0
         DKx               S              3  0
         DNextBit          S              1
         DByteOut          S              8
         ?*  Data Structures
         D                 DS
         DBinOut                       1200
         D  Octet                  1   1200    Dim(200)
         D                 DS
         DBits                     1      8    Inz(x'8040201008040201')
         DBit                      1      8    Dim(8)
         DTable            S             10    Inz('QTCPASC')
         ?*  Tables
         DOctIn            S              6    Dim(64) CtData PerRcd(1) Ascend
         DOctOut           S              1    Dim(64) CtData PerRcd(64)
         ?*  EBCDIC to ASCII translation
         D Translate       PR                  ExtPgm('QDCXLATE')
         D   Length                       5P 0 const
         D   Data                     32766A   options(*varsize)
         D   Table                       10A   const
         ?*
         C     *Entry        PList
         C                   Parm                    String
         C                   Parm                    StringOut
         ?*
         C     '  '          Scan      String        EndChar
         C                   If        EndChar = 0
         C                   Eval      EndChar = %Len(String)
         C                   Else
         C                   Eval      EndChar = EndChar - 1
         C                   Endif
         ?*  Convert to ASCII
         C                   CallP     Translate(%len(String):String:Table)
         ?*
         C                   For       Jx = 1 to EndChar
         C                   Eval      Char = %Subst(String:Jx:1)
         C                   Clear                   ByteOut
         ?*  Get binary
         C                   For       Ix = 1 to 8
         C                   Setoff                                       01
         C                   TestB     Bit(Ix)       Char                     01
         C                   If        *in01
         C                   Eval      NextBit = '1'
         C                   Else
         C                   Eval      NextBit = '0'
         C                   Endif
         C                   Eval      ByteOut = %Trim(ByteOut) + NextBit
         C                   EndFor
         C                   Eval      BinOut = %Trim(BinOut) + ByteOut
         ?*
         C                   EndFor
         ?*  Convert Octets to characters
         C                   Eval      Jx = 1
         C                   Dow       Octet(Jx) <> *Blanks
         C     ' ':'0'       Xlate     Octet(Jx)     Octet(Jx)
         C                   Eval      Kx = 1
         C     Octet(Jx)     LookUp    OctIn(Kx)                              99
         C                   Eval      StringOut = %Trim(StringOut) + OctOut(Kx)
         C                   Eval      Jx = Jx + 1
         C                   EndDo
         ?*
         C                   Seton                                        LR
    ** Octets
    000000
    000001
    000010
    000011
    000100
    000101
    000110
    000111
    001000
    001001
    001010
    001011
    001100
    001101
    001110
    001111
    010000
    010001
    010010
    010011
    010100
    010101
    010110
    010111
    011000
    011001
    011010
    011011
    011100
    011101
    011110
    011111
    100000
    100001
    100010
    100011
    100100
    100101
    100110
    100111
    101000
    101001
    101010
    101011
    101100
    101101
    101110
    101111
    110000
    110001
    110010
    110011
    110100
    110101
    110110
    110111
    111000
    111001
    111010
    111011
    111100
    111101
    111110
    111111
    ** Octet Output Values
    ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

    Comment


    • #3
      Re: Image in XML

      Hi Flodge,

      Thanks for your reply.

      Can you please send me the example to decode the this image.




      [!CDATA[uuencoded file is inserted here]!]
      IMAGE

      How can I decode it?

      PLease suggest.

      Thanks,
      Mini

      Comment


      • #4
        Re: Image in XML

        Hi

        I never had a reason to write a decoder. I'm a bit busy today, but if I find a gap I can write one because it seems like a fun thing to do.

        Comment


        • #5
          Re: Image in XML

          Flodge....You are a funny man I like that...


          Jamie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: Image in XML

            Thanks Flodge... :

            Comment


            • #7
              Re: Image in XML

              Hello

              Here is the MIME:Base64 decoder I promised you. It was fun to write. I hope you like it.

              I also attached a spreadsheet I made, which is useful for testing

              Code:
                   ?*
                   ?* CONTROL SPECIFICATION
                   ?*
                   H Debug
                   H DatEdit(*Ymd/)
                   H Option(*NoDebugIO)
                   H Aut(*All)
                   ?*  Fields
                   DString           S            200
                   DStringOut        S            150
                   DCharIn           S              1
                   DIx               S              3  0
                   DJx               S              3  0
                   DKx               S              3  0
                   DByteOut          S              1
                   DLengthIn         S              3S 0
                   DLengthOut        S              3  0
                   ?*  Data Structures
                   D                 DS
                   DTStringOut                    150
                   DCharOut                         1    Dim(150) Overlay(TStringOut)
                   D                 DS
                   DBinOut                       1200
                   D  Byte                   1   1200    Dim(150)
                   D                 DS
                   DBits                     1      8    Inz(x'8040201008040201')
                   DBit                      1      8    Dim(8)
                   DTable            S             10    Inz('QTCPEBC')
                   ?*  Tables
                   DOctIn            S              6    Dim(64) CtData PerRcd(1) Ascend
                   DOctOut           S              1    Dim(64) CtData PerRcd(64)
                   ?*  ASCII to EBCDIC translation
                   D Translate       PR                  ExtPgm('QDCXLATE')
                   D   Length                       5P 0 const
                   D   Data                     32766A   options(*varsize)
                   D   Table                       10A   const
                   ?*
                   C     *Entry        PList
                   C                   Parm                    String
                   C                   Parm                    StringOut
                   C                   Parm                    LengthIn
                   ?*
                   C                   Eval      LengthOut = LengthIn * 6/8
                   ?* Rebuild Binary String
                   C                   For       Ix = 1 to LengthIn
                   ?*
                   C                   Eval      CharIn = %Subst(String:Ix:1)
                   C                   Eval      Jx = 1
                   C     CharIn        Lookup    OctOut(Jx)                             99
                   C                   Eval      BinOut = %Trim(BinOut) + OctIn(Jx)
                   ?*
                   C                   EndFor
                   ?*
                   ?* Convert Binary String back to binary
                   C                   Clear                   TStringOut
                   C                   For       Jx = 1 to LengthOut
                   C                   Eval      ByteOut = x'00'
                   ?*
                   C                   For       Kx = 1 to 8
                   ?*
                   C                   If        %Subst(Byte(Jx):Kx:1) = '1'
                   C                   Biton     Bit(Kx)       ByteOut
                   C                   Endif
                   ?*
                   C                   Endfor
                   ?*
                   C                   CallP     Translate(1:ByteOut:Table)
                   C                   Eval      CharOut(Jx) = ByteOut
                   ?*
                   C                   EndFor
                   ?*
                   C                   Eval      StringOut = TStringOut
                   ?*
                   C                   Seton                                        LR
              ** Octets
              000000
              000001
              000010
              000011
              000100
              000101
              000110
              000111
              001000
              001001
              001010
              001011
              001100
              001101
              001110
              001111
              010000
              010001
              010010
              010011
              010100
              010101
              010110
              010111
              011000
              011001
              011010
              011011
              011100
              011101
              011110
              011111
              100000
              100001
              100010
              100011
              100100
              100101
              100110
              100111
              101000
              101001
              101010
              101011
              101100
              101101
              101110
              101111
              110000
              110001
              110010
              110011
              110100
              110101
              110110
              110111
              111000
              111001
              111010
              111011
              111100
              111101
              111110
              111111
              ** Octet Input Values
              ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
              Attached Files

              Comment

              Working...
              X