るりまサーチ

最速Rubyリファレンスマニュアル検索!
60件ヒット [1-60件を表示] (0.041秒)
トップページ > クエリ:>>[x] > クエリ:rexml/document[x]

別のキーワード

  1. rexml/document new
  2. rexml/document write
  3. rexml/document to_s
  4. rexml/document clone
  5. rexml/document node_type

検索結果

rexml/document (38102.0)

DOM スタイルの XML パーサ。

...スします。

以下のプログラムではブックマークの XML からデータを取り出します。

//emlist[][ruby]{
require 'rexml/document'
require 'pp'

Bookmark = Struct.new(:href, :title, :desc)

doc = REXML::Document.new(<<XML)
<?xml version="1.0" encoding="UTF-8" ?>
<xbel versi...
...e, desc)
end
pp bookmarks
# >> [#<struct Bookmark
# >> href="http://www.ruby-lang.org/ja/",
# >> title="オブジェクト指向スクリプト言語 Ruby",
# >> desc="Rubyの公式サイト">,
# >> #<struct Bookmark
# >> href="http://rurema.clear-code.com/",
# >> title="最速Rubyリフ...
...まサーチ",
# >> desc="Rubyリファレンスマニュアルを全文検索できる。\nとても便利。\n ">,
# >> #<struct Bookmark
# >> href="https://github.com/rurema/bitclust",
# >> title="rurema/bitclust · GitHub",
# >> desc=nil>,
# >> #<struct Bookmark
# >> href="https:/...

REXML::Formatters::Transitive (8054.0)

XMLドキュメントをテキストの内容を変えずに 多少の整形を加えて出力するクラスです。

...にたつかもしれません。
ただ、ほとんどの場合は奇妙な出力結果になるでしょう。

//emlist[][ruby]{
require 'rexml/document'
require 'rexml/formatters/transitive'
doc = REXML::Document.new <<EOS
<root><children>
<grandchildren foo='bar' />
</children></root>
EOS

tran...
...dren\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.first(doc, "/root/children")...

REXML::Element#each_element_with_attribute(key, value = nil, max = 0, name = nil) {|element| ... } -> () (8048.0)

特定の属性を持つすべての子要素を引数としてブロックを呼び出します。

...by]{
require 'rexml/document'
doc = REXML::Document.new("<a><b id='1'/><c id='2'/><d id='1'/><e/></a>")
doc.root.each_element_with_attribute('id'){|e| p e }
# >> <b id='1'/>
# >> <c id='2'/>
# >> <d id='1'/>
doc.root.each_element_with_attribute('id', '1'){|e| p e }
# >> <b id='1'/>
# >> <d id='1'/>...
...doc.root.each_element_with_attribute('id', '1', 1){|e| p e }
# >> <b id='1'/>
doc.root.each_element_with_attribute('id', '1', 0, 'd'){|e| p e }
# >> <d id='1'/>
//}...

REXML::Element#each_element_with_text(text = nil, max = 0, name = nil) {|element| ... } -> () (8048.0)

テキストを子ノードとして 持つすべての子要素を引数としてブロックを呼び出します。

...//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new '<a><b>b</b><c>b</c><d>d</d><e/></a>'
doc.root.each_element_with_text {|e|p e}
# >> <b> ... </>
# >> <c> ... </>
# >> <d> ... </>
doc.root.each_element_with_text('b'){|e|p e}
# >> <b> ... </>
# >> <c> ... </>
doc.root.each_elemen...
...t_with_text('b', 1){|e|p e}
# >> <b> ... </>
doc.root.each_element_with_text(nil, 0, 'd'){|e|p e}
# >> <d> ... </>
//}...

REXML::XPath.each(element, path = nil, namespaces = {}, variables = {}) {|e| ... } -> () (8018.0)

element の path で指定した XPath 文字列にマッチする各ノード に対してブロックを呼び出します。

...変数名とその値の対応付け

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<root xmlns:x='1'>
<a>
<b>b1</b>
<x:c />
<b>b2</b>
<d />
</a>
<b> b3 </b>
</root>
EOS

REXML::XPath.each(doc, "/root/a/b"){|e| p e.text }
# >> "b1"
# >> "b2"
//}...

絞り込み条件を変える