* lib/rexml/document.rb (REXML::Document#write): Document encoding
option. Now different encoding between XML file's encoding and XML declaration's encodiong is support. [Feature #4872] (work in progress) * lib/rexml/xmldecl.rb (REXML::XMLDecl#write): Always use XMLDecl's encoding. * test/rexml/test_document.rb: Update tests for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
69eedf6a18
commit
3f817764e2
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Sat Nov 3 12:49:45 2012 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
|
* lib/rexml/document.rb (REXML::Document#write): Document encoding
|
||||||
|
option. Now different encoding between XML file's encoding and
|
||||||
|
XML declaration's encodiong is support.
|
||||||
|
[Feature #4872] (work in progress)
|
||||||
|
* lib/rexml/xmldecl.rb (REXML::XMLDecl#write): Always use XMLDecl's
|
||||||
|
encoding.
|
||||||
|
* test/rexml/test_document.rb: Update tests for the above change.
|
||||||
|
|
||||||
Sat Nov 3 12:36:35 2012 Kouhei Sutou <kou@cozmixng.org>
|
Sat Nov 3 12:36:35 2012 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* lib/rexml/xmldecl.rb (REXML::XMLDecl): Stop using REXML::Encoding
|
* lib/rexml/xmldecl.rb (REXML::XMLDecl): Stop using REXML::Encoding
|
||||||
|
@ -145,8 +145,8 @@ module REXML
|
|||||||
end
|
end
|
||||||
|
|
||||||
# :call-seq:
|
# :call-seq:
|
||||||
# doc.write(output=$stdout, indent=-1, transtive=false, ie_hack=false)
|
# doc.write(output=$stdout, indent=-1, transtive=false, ie_hack=false, encoding=nil)
|
||||||
# doc.write(options={:output => $stdout, :indent => -1, :transtive => false, :ie_hack => false})
|
# doc.write(options={:output => $stdout, :indent => -1, :transtive => false, :ie_hack => false, :encoding => nil})
|
||||||
#
|
#
|
||||||
# Write the XML tree out, optionally with indent. This writes out the
|
# Write the XML tree out, optionally with indent. This writes out the
|
||||||
# entire XML document, including XML declarations, doctype declarations,
|
# entire XML document, including XML declarations, doctype declarations,
|
||||||
@ -199,6 +199,10 @@ module REXML
|
|||||||
# unable to parse proper XML, we have to provide a hack to generate XML
|
# unable to parse proper XML, we have to provide a hack to generate XML
|
||||||
# that IE's limited abilities can handle. This hack inserts a space
|
# that IE's limited abilities can handle. This hack inserts a space
|
||||||
# before the /> on empty tags. Defaults to false
|
# before the /> on empty tags. Defaults to false
|
||||||
|
# encoding::
|
||||||
|
# Encoding name as String. Change output encoding to specified encoding
|
||||||
|
# instead of encoding in XML declaration.
|
||||||
|
# Defaults to nil. It means encoding in XML declaration is used.
|
||||||
def write(*arguments)
|
def write(*arguments)
|
||||||
if arguments.size == 1 and arguments[0].class == Hash
|
if arguments.size == 1 and arguments[0].class == Hash
|
||||||
options = arguments[0]
|
options = arguments[0]
|
||||||
|
@ -44,11 +44,7 @@ module REXML
|
|||||||
def write(writer, indent=-1, transitive=false, ie_hack=false)
|
def write(writer, indent=-1, transitive=false, ie_hack=false)
|
||||||
return nil unless @writethis or writer.kind_of? Output
|
return nil unless @writethis or writer.kind_of? Output
|
||||||
writer << START.sub(/\\/u, '')
|
writer << START.sub(/\\/u, '')
|
||||||
if writer.kind_of? Output
|
writer << " #{content encoding}"
|
||||||
writer << " #{content writer.encoding}"
|
|
||||||
else
|
|
||||||
writer << " #{content encoding}"
|
|
||||||
end
|
|
||||||
writer << STOP.sub(/\\/u, '')
|
writer << STOP.sub(/\\/u, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -165,11 +165,16 @@ EOX
|
|||||||
indent = -1
|
indent = -1
|
||||||
transitive = false
|
transitive = false
|
||||||
ie_hack = false
|
ie_hack = false
|
||||||
encoding = "Shift_JIS"
|
encoding = "Windows-31J"
|
||||||
|
|
||||||
|
xml_declaration_encoding = "Shift_JIS"
|
||||||
|
@document.xml_decl.encoding = xml_declaration_encoding
|
||||||
|
japanese_text = "こんにちは"
|
||||||
|
@document.root.text = japanese_text
|
||||||
@document.write(output, indent, transitive, ie_hack, encoding)
|
@document.write(output, indent, transitive, ie_hack, encoding)
|
||||||
assert_equal(<<-EOX, output)
|
assert_equal(<<-EOX.encode(encoding), output)
|
||||||
<?xml version='1.0' encoding='SHIFT_JIS'?>
|
<?xml version='1.0' encoding='#{xml_declaration_encoding}'?>
|
||||||
<message>Hello world!</message>
|
<message>#{japanese_text}</message>
|
||||||
EOX
|
EOX
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -215,10 +220,15 @@ EOX
|
|||||||
|
|
||||||
def test_encoding
|
def test_encoding
|
||||||
output = ""
|
output = ""
|
||||||
@document.write(:output => output, :encoding => "Shift_JIS")
|
encoding = "Windows-31J"
|
||||||
assert_equal(<<-EOX, output)
|
xml_declaration_encoding = "Shift_JIS"
|
||||||
<?xml version='1.0' encoding='SHIFT_JIS'?>
|
@document.xml_decl.encoding = xml_declaration_encoding
|
||||||
<message>Hello world!</message>
|
japanese_text = "こんにちは"
|
||||||
|
@document.root.text = japanese_text
|
||||||
|
@document.write(:output => output, :encoding => encoding)
|
||||||
|
assert_equal(<<-EOX.encode(encoding), output)
|
||||||
|
<?xml version='1.0' encoding='#{xml_declaration_encoding}'?>
|
||||||
|
<message>#{japanese_text}</message>
|
||||||
EOX
|
EOX
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user