lunes, 27 de abril de 2009

AAP BloqueT2.10 ejercicio1

Hacer un filtro SAX que traduzca el célebre XML casero de etiquetas en español a etiquetas en inglés. Hacerlo en Ruby o en otro lenguaje.
Para probarlo descargar estos dos archivos:
equipo.xml
bloqueT210.rb
#!/usr/bin/ruby
require 'rexml/document'
require 'rexml/streamlistener'
include REXML
entrada='./equipo.xml'


diccionario = {"equipo"=>"team",
"jugador"=>"player",
"nombre"=>"name",
"posicion"=>"position",
"numero"=>"number",
"entrenador"=>"coach",
"Portero"=>"Goalkeeper",
"Amigo del portero"=>"Friend of the goalkeeper",
"La fan de Mortadelo"=>"The fan of Mortadelo"}

class Traduce
include StreamListener
def initialize(dic)
@escribe = false
@diccionario = dic
end

def tag_start(name, attributes)
puts "<"+@diccionario[name]+">"
@escribe = true
end

def tag_end(name)
puts "</"+@diccionario[name]+">"
@escribe=false
end

def text(texto)
if @escribe
if @diccionario[texto]
puts @diccionario[texto]
else
puts texto
end
end
end
end

print "Content-Type: application/xhtml+xml\n\n"

listener = Traduce.new(diccionario)
parser = Parsers::StreamParser.new(File.new(entrada), listener)
parser.parse

1 comentario:

  1. Additionally, gamers in states that have but to control playing usually play stay supplier video games via on-line platforms based mostly in other jurisdictions. One downside of the US market is that operators are limited to a primary recreation selection. Live casino 먹튀사이트 먹튀프렌즈3 studios have to be located in the state the place they function, and organising studios in a number of} states would see bills add up in a short time}. Players have totally different motives and preferences when enjoying in} on-line casino video games.

    ResponderEliminar