48件ヒット
[1-48件を表示]
(0.150秒)
別のキーワード
ライブラリ
-
rexml
/ document (36) - stringio (12)
キーワード
- Default (12)
- Pretty (12)
- Transitive (12)
検索結果
-
StringIO (50055.0)
-
文字列に IO と同じインタフェースを持たせるためのクラスです。
...のクラスです。
//emlist[例][ruby]{
require "stringio"
sio = StringIO.new("hoge", 'r+')
p sio.read #=> "hoge"
sio.rewind
p sio.read(1) #=> "h"
sio.write("OGE")
sio.rewind
p sio.read #=> "hOGE"
//}
=== 例外
StringIO オブジェクトは大抵......の場合 IO オブジェクトと同じ例外を発生させます。
例えば次の例では write は IOError を発生させます。
//emlist[例][ruby]{
require "stringio"
sio = StringIO.new("hoge")
sio.close
sio.write("a")
# => in `write': not opened for writing (IOError)
//}... -
REXML
:: Formatters :: Pretty (9025.0) -
XMLドキュメントを(文字列として)見た目良く出力するクラスです。
...matters::Default と
異なり見た目のためテキストの改行や空白を修正して出力します。
//emlist[][ruby]{
require 'rexml/document'
require 'rexml/formatters/pretty'
doc = REXML::Document.new <<EOS
<root>
<children>
<grandchildren foo='bar'/>
</children>
</root>
EOS
pretty......_formatter = REXML::Formatters::Pretty.new
output = StringIO.new
pretty_formatter.write(doc, output)
output.string
# => "<root>\n <children>\n <grandchildren foo='bar'/>\n </children>\n</root>"
# この出力結果は入力のXMLよりも空白が増えている
//}... -
REXML
:: Formatters :: Default (6049.0) -
XMLドキュメントを(文字列として)出力するクラスです。
...rmatters::Pretty と
異なりテキストの改行や空白を修正せずにそのまま出力します。
//emlist[][ruby]{
require 'rexml/document'
require 'rexml/formatters/default'
doc = REXML::Document.new <<EOS
<root>
<children>
<grandchildren/>
</children>
</root>
EOS
default_formatter......= REXML::Formatters::Default.new
output = StringIO.new
default_formatter.write(doc, output)
output.string
# => "<root>\n<children>\n <grandchildren/>\n</children>\n</root>\n"
output = StringIO.new
default_formatter.write(REXML::XPath.first(doc, "/root/children"), output)
output.string
# => "<child......ren>\n <grandchildren/>\n</children>"
ie_hack_formatter = REXML::Formatters::Default.new(true)
output = StringIO.new
ie_hack_formatter.write(doc, output)
output.string
# => "<root>\n<children>\n <grandchildren />\n</children>\n</root>\n"
//}... -
REXML
:: Formatters :: Transitive (6043.0) -
XMLドキュメントをテキストの内容を変えずに 多少の整形を加えて出力するクラスです。
...t[][ruby]{
require 'rexml/document'
require 'rexml/formatters/transitive'
doc = REXML::Document.new <<EOS
<root><children>
<grandchildren foo='bar' />
</children></root>
EOS
transitive_formatter = REXML::Formatters::Transitive.new
output = StringIO.new
transitive_formatter.write(doc, output)
output.......string
# => "<root\n><children\n >\n<grandchildren foo='bar'\n />\n</children\n ></root\n>\n"
print output.string
# >> <root
# >> ><children
# >> >
# >> <grandchildren foo='bar'
# >> />
# >> </children
# >> ></root
# >> >
output = StringIO.new
transitive_formatter.write(REXML::XPath.f......irst(doc, "/root/children"), output)
output.string
# => "<children\n>\n<grandchildren foo='bar'\n />\n</children\n>"
//}...