Kuriyama
04-01-2008, 01:25 PM
I'm attempting to use a XML file to read in form labels based on a selected language. The problem is that I'm not able to display unicode. Letters with accents on them are not appearing correctly. Any ideas?
XML snippet
<?xml version="1.0" encoding="utf-8" ?>
<formlabels>
<firstname>
<english>First Name</english>
<spanish>Nombre</spanish>
<jibberish>AKSJso@</jibberish>
</firstname>
<lastname>
<english>Last Name</english>
<spanish>Nombre Pasado</spanish>
<jibberish>lkjasdf987</jibberish>
</lastname>
.. .
ASP snippet
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" />
<html>
<head>
<title>testing</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<%
function getFormLabelsByLanguage(strTargetLang)
strTargetLang = Lcase(trim(strTargetLang))
Set objScriptDict = Server.CreateObject("Scripting.Dictionary")
Set objParser = Server.CreateObject("Microsoft.XMLDOM")
objParser.async = true
objParser.Load(Server.MapPath("form_label.xml"))
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Grab all the labels we have for a certain language
''''''''''''''''''''''''''''''''''''''''''''''''''''
set objList = objParser.getElementsByTagName(strTargetLang)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Put all of the name value pairs into a scripting dictonary
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
for i=0 to (objList.length - 1)
strNode = objList.item(i).parentNode.nodeName
strValue = objList.item(i).text
objScriptDict.add strNode, strValue
next
set objParser = nothing
set getFormLabelsByLanguage = objScriptDict
set objScriptDict = nothing
end function
%>
XML form prototype
<br />
<br />
Be default this form will display in english.
<br />
<form method="get" action="index.asp">
<select name="lang">
<option value="english">English</option>
<option value="spanish">Spanish</option>
<option value="jibberish">Jibberish?</option>
<option value="chinese">Chinese</option>
</select>
<input type="submit" />
</form>
<br />
<hr />
<%
strLang = Request("lang")
if strLang = "" then
strLang = LCase(session("language"))
end if
''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Pull the correct labels based on language selection.
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objForm = Server.CreateObject("Scripting.Dictionary")
set objForm = getformLabelsByLanguage(strLang)
Response.write isNull(objBean)
%>
<form method="get" action="index.asp">
<table>
<tr>
<td><%=objForm("firstname") %></td>
<td><input type="text" value="<%=Request("fname")%>" name="fname" /></td>
</tr>
<tr>
<td><%=objForm("lastname")%></td>
<td><input type="text" value="<%=Request("lname")%>" name="lname" /></td>
</tr>
<tr>
<td><%=objForm("city") %></td>
<td><input type="text" value="<%=Request("city") %>" name="city" /></td>
</tr>
<tr>
<td><%=objForm("phone")%></td>
<td><input type="text" value="<%=Request("phone") %>" name="phone" /></td>
</tr>
</table>
<input type="submit" />
</form>
</body>
</html>
<%set objForm= nothing %>
XML snippet
<?xml version="1.0" encoding="utf-8" ?>
<formlabels>
<firstname>
<english>First Name</english>
<spanish>Nombre</spanish>
<jibberish>AKSJso@</jibberish>
</firstname>
<lastname>
<english>Last Name</english>
<spanish>Nombre Pasado</spanish>
<jibberish>lkjasdf987</jibberish>
</lastname>
.. .
ASP snippet
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" />
<html>
<head>
<title>testing</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<%
function getFormLabelsByLanguage(strTargetLang)
strTargetLang = Lcase(trim(strTargetLang))
Set objScriptDict = Server.CreateObject("Scripting.Dictionary")
Set objParser = Server.CreateObject("Microsoft.XMLDOM")
objParser.async = true
objParser.Load(Server.MapPath("form_label.xml"))
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Grab all the labels we have for a certain language
''''''''''''''''''''''''''''''''''''''''''''''''''''
set objList = objParser.getElementsByTagName(strTargetLang)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Put all of the name value pairs into a scripting dictonary
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
for i=0 to (objList.length - 1)
strNode = objList.item(i).parentNode.nodeName
strValue = objList.item(i).text
objScriptDict.add strNode, strValue
next
set objParser = nothing
set getFormLabelsByLanguage = objScriptDict
set objScriptDict = nothing
end function
%>
XML form prototype
<br />
<br />
Be default this form will display in english.
<br />
<form method="get" action="index.asp">
<select name="lang">
<option value="english">English</option>
<option value="spanish">Spanish</option>
<option value="jibberish">Jibberish?</option>
<option value="chinese">Chinese</option>
</select>
<input type="submit" />
</form>
<br />
<hr />
<%
strLang = Request("lang")
if strLang = "" then
strLang = LCase(session("language"))
end if
''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Pull the correct labels based on language selection.
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objForm = Server.CreateObject("Scripting.Dictionary")
set objForm = getformLabelsByLanguage(strLang)
Response.write isNull(objBean)
%>
<form method="get" action="index.asp">
<table>
<tr>
<td><%=objForm("firstname") %></td>
<td><input type="text" value="<%=Request("fname")%>" name="fname" /></td>
</tr>
<tr>
<td><%=objForm("lastname")%></td>
<td><input type="text" value="<%=Request("lname")%>" name="lname" /></td>
</tr>
<tr>
<td><%=objForm("city") %></td>
<td><input type="text" value="<%=Request("city") %>" name="city" /></td>
</tr>
<tr>
<td><%=objForm("phone")%></td>
<td><input type="text" value="<%=Request("phone") %>" name="phone" /></td>
</tr>
</table>
<input type="submit" />
</form>
</body>
</html>
<%set objForm= nothing %>