Sha256: de681f02b537ad0cf78eb74205df011b3b451faeadc090f6499fe0d2fd086237

Contents?: true

Size: 1.7 KB

Versions: 4

Compression:

Stored size: 1.7 KB

Contents

#!/usr/bin/env ruby -wW1
# encoding: UTF-8

$: << File.join(File.dirname(__FILE__), "../lib")
$: << File.join(File.dirname(__FILE__), "../ext")

require 'stringio'
require 'ox'

x1 = %(<?xml version="1.0" encoding="ISO-8859-1" ?><tag key="value">Français</tag>).encode("ISO-8859-1")
# => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?><tag key=\"value\">Fran\xE7ais</tag>" 
x1.encoding
# => #<Encoding:ISO-8859-1> 

x2 = %(<?xml version="1.0" encoding="UTF-8" ?><tag key="value">Français</tag>)
# => "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><tag key=\"value\">Fran\xC3\xA7ais</tag>"
x2.encoding
# => #<Encoding:UTF-8> 

class OH < ::Ox::Sax
  def start_element(name)
    puts "EL: #{name} (#{name.encoding})"
  end

  def end_element(name)
  end

  def attr(key, value)
    puts "AT: #{key} => #{value} (#{key.encoding} => #{value.encoding})"
  end

  def text(value)
    puts "TX: #{value} (#{value.encoding})"
  end
end

::Ox.sax_parse OH.new, StringIO.new(x1)
   # => AT: version => 1.0 (US-ASCII => ASCII-8BIT)
   #    AT: encoding => ISO-8859-1 (US-ASCII => ISO-8859-1)
   #    EL: tag (US-ASCII)
   #    AT: key => value (US-ASCII => ISO-8859-1)
   #    TX: Fran�ais (ISO-8859-1)

puts

::Ox.sax_parse OH.new, StringIO.new(x2)
   # => AT: version => 1.0 (US-ASCII => ASCII-8BIT)
   #    AT: encoding => UTF-8 (US-ASCII => UTF-8)
   #    EL: tag (US-ASCII)
   #    AT: key => value (US-ASCII => UTF-8)
   #    TX: Français (UTF-8)

puts
x3 = %(<?xml version="1.0" encoding="ISO-8859-1" ?><tag Português="Español">Français</tag>).encode("ISO-8859-1")
::Ox.sax_parse OH.new, StringIO.new(x3)

puts
x4 = %(<?xml version="1.0" encoding="UTF-8" ?><tag Português="Español">Français</tag>)
::Ox.sax_parse OH.new, StringIO.new(x4)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ox-1.5.2 test/bug4.rb
ox-1.5.0 test/bug4.rb
ox-1.4.6 test/bug4.rb
ox-1.4.5 test/bug4.rb