WFS iso-8859-1 to utf-8

Daniel Morissette dmorissette at MAPGEARS.COM
Fri Oct 26 09:21:07 EDT 2007


Hint: If someone filed a ticket in Trac describing the issue and 
suggesting the addition of support in MapServer for converting encoding 
of attribute values while generating GML then that would significantly 
increase the chances of this being implemented in a future release, 
possibly even in 5.2.  ;)

Daniel

Arnd Wippermann wrote:
> Hi,
> 
> after the release of OpenLayers 2.5 I have looked at WFS. Loading the
> geometry with OpenLayers from MapServer works. But to retrieve the
> attributes in the right way (utf-8) is in some way difficult.
> 
> For IIS I have found a solution, that takes input in i.e "ISO-8859-1" and
> creates UTF-8. 
> 
> I use a wrapper-script, that 1. hides the real OnlineResource and 2. convert
> the input to utf-8.
> 
> The script (ported to vbscript) can also used to convert local xml-files to
> utf-8.
> 
> Perhaps someone have an idea to do this in python or php for the use with
> apache. I have no clue, how to do this.
> 
> <%
>     Option Explicit
> 
>     'usage : http://this.asp 'without parameter the xmlString will converted
> and send to the browser
>     '
>     'or      http://this.asp?WFS-Parameter
> 
>     Dim strRequest
> 
>     Select Case Request.ServerVariables("REQUEST_METHOD")
>       Case "GET"  strRequest = Request.QueryString
>       Case "POST" strRequest = Request.Form
>     End Select
> 
>     Call Haurein
> 
>     Sub haurein()
> 
>         Dim testLocal
>         if strRequest = "" then
>             testLocal = true
>         else
>             testLocal = false
>         end if
> 
>         Dim xmlString 'for local test
> 
>         xmlString =             "<?xml version=""1.0""
> encoding=""ISO-8859-1""?>" & vbCrLf
>         xmlString = XMLString & "<document>" & vbCrLf
>         xmlString = XMLString & "  <tagOne>ein Ä - ä, Straße,
> Überlauf</tagOne>" & vbCrLf
>         xmlString = XMLString & "  <tagOne>ein Ö - ö</tagOne>" & vbCrLf
>         xmlString = XMLString & "  <tagOne>ein Ü - ü # é, á</tagOne>" &
> vbCrLf
>         xmlString = XMLString & "  <tagOne>#ä#ö#ü#ß - Ä#Ö#Ü#</tagOne>" &
> vbCrLf
>         xmlString = XMLString & "</document>" & vbCrLf
> 
>         Dim mapserv, strURL
>         if testLocal = false then
>             mapserv = "http://[mapserv.exe]?map=[mapfile]"
>             strURL  = mapserv & "&" & strRequest
>         end if
> 
>     'response.write strURL
> 
>         'Create new XML object for conversion and load xmlString or request
> and load the WFS
>         Dim oDOM
>         Set oDOM = Server.CreateObject("Microsoft.XMLDOM")
>         if testLocal then
>             oDOM.loadXML(xmlString)
>         else
>             Dim objHTTP
>             Set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
> 
>             On Error Resume Next
>             'get the WFS response
>             objHTTP.open "GET", URLDecode(strURL), false
>             if err.number <> 0 then
>                 Response.Write err.description & "<br><b>testLocal</b> : " &
> testLocal & "<br><b>mapserv</b> : " & mapserv & "<br><b>strRequest</b> : " &
> strRequest
>                 Exit Sub
>             end if
>             objHTTP.send ""
> 
>             'declare the original charset
>             Response.CharSet     = "ISO-8859-1"
>             Response.ContentType = "text/xml"
> 
>             oDOM.load(objHTTP.responseXML)
>         end if
> 
>         'Replace the processing instruction of the XML object
>         Dim pi
>         Set pi = oDOM.createProcessingInstruction("xml", "version=""1.0""
> encoding=""utf-8""")
>         oDOM.replaceChild pi, oDOM.childNodes.item(0)
> 
>         'declare the charset of the output
>         Response.CharSet     = "UTF-8"
>         Response.ContentType = "text/xml"
>         oDOM.save(Response)
> 
>         Set objHTTP = Nothing
>         Set oDOM    = Nothing
>         Set pi      = Nothing
> 
>     End Sub
> 
>     ' An inverse to Server.URLEncode
>     function URLDecode(str)
>     	dim re
>     	set re = new RegExp
> 
>     	str = Replace(str, "+", " ")
> 
>     	re.Pattern = "%([0-9a-fA-F]{2})"
>     	re.Global = True
>     	URLDecode = re.Replace(str, GetRef("URLDecodeHex"))
>     end function
> 
>     ' Replacement function for the above
>     function URLDecodeHex(match, hex_digits, pos, source)
>     	URLDecodeHex = chr("&H" & hex_digits)
>     end function
> 
> %>
> 
> Mit freundlichen Grüssen
> 
> Arnd Wippermann
> http://gis.ibbeck.de/ginfo/


-- 
Daniel Morissette
http://www.mapgears.com/



More information about the mapserver-users mailing list