locked
WML Output Encoding RRS feed

  • Question

  • User-1820843917 posted
    Hi, is there any way to force mobile web forms to generate wml code starting with:
    <?xml version="1.0" encoding="utf-8"?>
    instead of
    <?xml version='1.0' ?> .

    Currently some phones do not display correctly cyrillic characters  of wml generated by mobile webforms. But the same phones correctly display static wml pages that has encoding="utf-8" specyfied.
    Thanks
    Thursday, September 28, 2006 8:09 AM

All replies

  • User-1820843917 posted

    Found a solution !

    Wrote custom Filter for attaching to Response objects Filter property:

     

    1    public class ResponseFilterStream : Stream
    2    {
    3        private Stream stream;
    4        private StreamWriter streamWriter;
    5    
    6        public ResponseFilterStream(Stream stm)
    7        {
    8            stream = stm;
    9            //streamWriter = new StreamWriter(stream, Encoding.UTF8);
    10           streamWriter = new StreamWriter(stream);
    11       }
    12   
    13       public override void Write(byte[] buffer, int offset, int count)
    14       {
    15           MemoryStream ms = new MemoryStream(buffer, offset, count, false);
    16           //StreamReader sr = new StreamReader(ms, Encoding.UTF8);
    17           StreamReader sr = new StreamReader(ms);
    18           string s;
    19           
    20           while ((s = sr.ReadLine()) != null)
    21           {
    22               //s = s.Trim();
    23               
    24               if (s != "")
    25               {
    26                   if (s.StartsWith("<?xml version"))
    27                   {
    28                       streamWriter.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    29                   }
    30                   else
    31                   {
    32                       streamWriter.Write(s);
    33                   }
    34                   streamWriter.WriteLine();
    35               }
    36           }
    37           streamWriter.Flush();
    38       }
    39   
    40       #region Rest of Stream's function - our stream is write-only
    41   
    42       public override int Read(byte[] buffer, int offset, int count)
    43       {
    44           throw new NotSupportedException();
    45       }
    46   
    47       public override bool CanRead
    48       {
    49           get { return false; }
    50       }
    51   
    52       public override bool CanSeek
    53       {
    54           get { return false; }
    55       }
    56   
    57       public override bool CanWrite
    58       {
    59           get { return true; }
    60       }
    61   
    62       public override long Length
    63       {
    64           get { throw new NotSupportedException(); }
    65       }
    66   
    67       public override long Position
    68       {
    69           get { throw new NotSupportedException(); }
    70           set { throw new NotSupportedException(); }
    71       }
    72   
    73       public override void Flush()
    74       {
    75           stream.Flush();
    76       }
    77   
    78       public override long Seek(long offset, SeekOrigin origin)
    79       {
    80           throw new NotSupportedException();
    81       }
    82   
    83       public override void SetLength(long value)
    84       {
    85           throw new NotSupportedException();
    86       }
    87   
    88       #endregion
    89   }
    

      

    Attached newly created Filter in Global.asax

     

    1    protected void Application_PostRequestHandlerExecute(object sender, EventArgs e)
    2        {
    3            if (Response.ContentType == "text/vnd.wap.wml")
    4                Response.Filter = new ResponseFilterStream(Response.Filter);
    5        }
    

     

     

    Friday, October 6, 2006 1:06 AM