Nuestra clase clsIdioma
Una vez visto como funciona esto de moverse entre los nodos, nos encaminamos a crear las funciones que vamos a utilizar para acceder a la información. Por el momento van a ser de tres tipos:
1 – Genérico: Para obtener los títulos, nombres, texto en general. Por ejemplo: Los botones de un formulario (aceptar, cancelar, imprimir…) o las etiquetas de un formulario: nombre, apellido, dirección, Código Postal. Incluso podemos por trozos enteros de código HTML usando secciones CDATA.
2 – Menu Principal: Este nodo contiene el texto del menú principal, sus enlaces, incluso su target.
3 – El bloque de Idiomas Disponibles: Contendrá los textos y los enlaces que queramos usar.
El Código de clsIdioma
Código:
<%
Const adInteger = 3
Const adVarChar = 200
Const adDate = 7
Class clsIdioma
private idiomaXML
public function Load(strIdioma)
if len(strIdioma) > 0 then
idiomaXML.load(strIdioma)
' Procesamos los errores de lectura
if idiomaXML.parseError.errorCode <> 0 Then
Load = "Error de Lectura (Por favor, ponerse en contacto con el webmaster).<br />FilePos: " & idiomaXML.parseError.filepos & "<br /> Línea: " & idiomaXML.parseError.Line & "<br /> Causa: " & idiomaXML.parseError.reason & "<br /> Ocurrió en: " & idiomaXML.parseError.srcText & "<br /> Archivo: " & idiomaXML.parseError.URL
else
Load = ""
end if
else
Load = "¡Nada que leer!"
end if
end function
Public function GetIdioma(etiqueta)
Dim Texto
on error resume next
Texto = idiomaXML.getElementsByTagName(etiqueta).Item(0).Text
if err.number > 0 then
GetIdioma = "[" & etiqueta & "]"
else
getidioma=texto
end if
on error goto 0
end function
Public function getMenus()
Dim n, num, arr()
Dim rs
num = idiomaXML.selectSingleNode("/Idioma/menues").childNodes.length
if num = 0 then 'Ha habido un problema cargando el xml
set getMenus = nothing
exit function
end if
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Fields.Append "url", adVarChar, 255
rs.Fields.Append "texto", adVarChar, 255
rs.Fields.Append "target", adVarChar, 25
rs.Open
for n = 0 to num - 1
rs.AddNew
rs.Fields("url").Value = idiomaXML.selectSingleNode("/Idioma/menues").childNodes(n).attributes(0).Value ' url
rs.Fields("target").Value = idiomaXML.selectSingleNode("/Idioma/menues").childNodes(n).attributes(1).Value ' target
rs.Fields("texto").Value = idiomaXML.selectSingleNode("/Idioma/menues").childNodes(n).childNodes(0).text ' texto
rs.Update
next
rs.moveFirst
set getMenus = rs
set rs = nothing
end function
Public function getLangMenus()
Dim n, num, arr()
Dim rs
num = idiomaXML.selectSingleNode("/Idioma/menuIdiomas").childNodes.length
if num = 0 then 'Ha habido un problema cargando el xml
set getMenus = nothing
exit function
end if
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Fields.Append "id", adVarChar, 2
rs.Fields.Append "imgUrl", adVarChar, 255
rs.Fields.Append "alt", adVarChar, 50
rs.Open
for n = 0 to num - 1
rs.AddNew
rs.Fields("id").Value = idiomaXML.selectSingleNode("/Idioma/menuIdiomas").childNodes(n).attributes(0).Value ' id
rs.Fields("imgUrl").Value = idiomaXML.selectSingleNode("/Idioma/menuIdiomas").childNodes(n).attributes(1).Value ' imgUrl
rs.Fields("alt").Value = idiomaXML.selectSingleNode("/Idioma/menuIdiomas").childNodes(n).attributes(2).Value ' alt
rs.Update
next
rs.moveFirst
set getLangMenus = rs
set rs = nothing
end function
'*********************************************************************
' Inicializacion/Terminacion
'*********************************************************************
Private Sub Class_Initialize()
Set idiomaXML = Server.CreateObject("Microsoft.XMLDOM")
' Para evitar que el objeto esté en escucha ya que
' solo lo vamos a abrir una vez
idiomaXML.async=false
End Sub
Private Sub Class_Terminate()
Set idiomaXML = Nothing
End Sub
end Class
%>