るりまサーチ (Ruby 2.3.0)

最速Rubyリファレンスマニュアル検索!
123件ヒット [1-100件を表示] (0.042秒)
トップページ > バージョン:2.3.0[x] > クエリ:new[x] > ライブラリ:rexml[x]

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

モジュール

検索結果

<< 1 2 > >>

REXML::Text.new(arg, respect_whitespace = false, parent = nil, raw = nil, entity_filter = nil, illegal = REXML::Text::NEEDS_A_SECOND_CHECK) (54451.0)

テキストノードオブジェクトを生成します。

...ジェクトを生成します。

arg でノードの内容を指定します。
文字列の場合はそれが内容として使われます。
REXML
::Text オブジェクトの場合はその内容が複製されます。

respect_whitespace に真を指定すると、arg に含まれる空白文...
...あると解釈され、
rexml
はテキストに含まれているすべての(定義済み)実体を
エスケープします
nilの場合、親ノードが raw モードであるかどうかで
self が raw モードになるかどうかが決まります。
arg に REXML::Text オブジェクト...
...(デフォルトの場合)、
テキストがどのようにエスケープされるかは、そのノードが属する
文書(REXML::Document)の
DTD(REXML::DocType, REXML::Document#doctype)
で定義されます。DTD が与えられていない場合は、XMLの規格上
以下の実体参照/...

REXML::CData.new(text, respect_whitespace = true, parent = nil) -> REXML::CData (54397.0)

text をテキストとして持つ CData オブジェクトを生成します。

...uire 'rexml/document'
doc = REXML::Document.new(<<EOS)
<root />
EOS
doc.root.add(REXML::CData.new("foo bar baz "))
doc.to_s # => "<root><![CDATA[foo bar baz ]]></root>\n"

doc = REXML::Document.new(<<EOS)
<root />
EOS
doc.root.add(REXML::CData.new("foo bar baz ", true))
doc.root.add(REXML::CDat...

REXML::DocType.new(source, parent = nil) -> REXML::DocType (54361.0)

DocType オブジェクトを生成します。

...オブジェクトを生成します。

REXML
::Source オブジェクトの場合は、Source オブジェクトが
保持しているDTDのテキストがパースされ、その内容によって DocType
オブジェクトが初期化されます。
REXML
::DocType.new(Source.new(<<EOS))
<!DO...
...スもありますが、内部用なので使わないで
ください。

一般的にいって、XML 文書に含まれる DTD は REXML::Document.new などで
適切に解析され、REXML::Document#doctype で取得できます。
このメソッドを直接使う必要はありません。...

REXML::Entity.new(array) -> REXML::Entity (54346.0)

新たな Entity オブジェクトを生成して返します。

...ty オブジェクトが欲しい場合は、
文書に適切な DTD を含めておいてそれを REXML::Document.new で
パースするようにしてください。

配列を使うほうは rexml のパーサが内部的に利用するため通常は利用しません。

@param name 実体参...
...照の名前
@param value 参照の値
@param parent 親ノード
@param reference パラメータ実体であるかどうかの真偽値
@param array 初期化のための配列

=== 例
「&gt;」「>」 の対応は以下のように実現されます。
REXML
::Entity.new("gt", ">")...

REXML::Entity.new(name, value, parent=nil, reference=false) -> REXML::Entity (54346.0)

新たな Entity オブジェクトを生成して返します。

...ty オブジェクトが欲しい場合は、
文書に適切な DTD を含めておいてそれを REXML::Document.new で
パースするようにしてください。

配列を使うほうは rexml のパーサが内部的に利用するため通常は利用しません。

@param name 実体参...
...照の名前
@param value 参照の値
@param parent 親ノード
@param reference パラメータ実体であるかどうかの真偽値
@param array 初期化のための配列

=== 例
「&gt;」「>」 の対応は以下のように実現されます。
REXML
::Entity.new("gt", ">")...

絞り込み条件を変える

REXML::Element.new(arg = UNDEFINED, parent = nil, context = nil) -> REXML::Element (54343.0)

要素オブジェクトを生成します。

... REXML::Element オブジェクトの場合は、
新たな要素の名前、属性、context が arg のもので初期化されます。

parent で親ノードを指定します。

context には hash table で要素のコンテキストを指定します。
基本的には text node (REXML::...
...
また、すべての要素で空白を考慮して欲しい場合には
:all を指定します。
デフォルト値は :all です。
REXML
::Element#whitespace も参照してください。
: :compress_whitespace
空白を無視して欲しい要素の名前の集合を文字列の...
...ect_whitespace での指定を上書きします。
すべての要素で空白を無視して欲しい場合には
:all を指定します。
REXML
::Element#whitespace も参照してください。
: :ignore_whitespace_nodes
空白のみからなるノードを無視して欲しい要素...

REXML::Attributes.new(element) -> REXML::Attributes (54325.0)

空の Attributes オブジェクトを生成します。

...どの要素の属性であるかを element で指定します。

通常は REXML::Element.new によって Attributes オブジェクト
が生成されるため、このメソッドを使う必要はありません。

@param element 属性が属する要素(REXML::Element オブジェクト)...

REXML::Elements.new(parent) -> REXML::Elements (54325.0)

空の要素の集合を表すオブジェクトを生成します。

...空の要素の集合を表すオブジェクトを生成します。

通常は REXML::Element.new によって Elements オブジェクトが
生成されるため、このメソッドを使う必要はありません。

@param parant 親要素オブジェクト...

REXML::Attribute.new(attribute, value, parent = nil) -> REXML::Attribute (54310.0)

新たな属性オブジェクトを生成します。

...新たな属性オブジェクトを生成します。

2種類の初期化が可能です。
REXML
::Attribute オブジェクトを渡した場合は、
属性名とその値がそれから複製されます。
parent で新たに作られる属性オブジェクトが属する
要素が指定で...
...ソッドは直接は使わず、REXML::Element#add_attribute などを
使うでしょう。

@param attribute_to_clone 複製元の REXML::Attribute オブジェクト
@param attribute 属性名
@param value 属性の値
@param parent 生成される属性が所属する要素(REXML::Element)...

REXML::Attribute.new(attribute_to_clone, parent = nil) -> REXML::Attribute (54310.0)

新たな属性オブジェクトを生成します。

...新たな属性オブジェクトを生成します。

2種類の初期化が可能です。
REXML
::Attribute オブジェクトを渡した場合は、
属性名とその値がそれから複製されます。
parent で新たに作られる属性オブジェクトが属する
要素が指定で...
...ソッドは直接は使わず、REXML::Element#add_attribute などを
使うでしょう。

@param attribute_to_clone 複製元の REXML::Attribute オブジェクト
@param attribute 属性名
@param value 属性の値
@param parent 生成される属性が所属する要素(REXML::Element)...

絞り込み条件を変える

REXML::Comment.new(comment, parent = nil) -> REXML::Comment (54310.0)

Comment オブジェクトを生成します。

...mment オブジェクトを生成します。

引数に REXML::Comment オブジェクトを渡すとその内容が複製されます
(親ノードの情報は複製されません)。

@param string コメント文字列
@param comment REXML::Comment オブジェクト
@param parent 親ノード...

REXML::Comment.new(string, parent = nil) -> REXML::Comment (54310.0)

Comment オブジェクトを生成します。

...mment オブジェクトを生成します。

引数に REXML::Comment オブジェクトを渡すとその内容が複製されます
(親ノードの情報は複製されません)。

@param string コメント文字列
@param comment REXML::Comment オブジェクト
@param parent 親ノード...

REXML::AttlistDecl.new(source) -> REXML::AttlistDecl (54307.0)

このメソッドは内部用なので使わないでください。

このメソッドは内部用なので使わないでください。

REXML::Child.new(parent = nil) -> REXML::Child (54307.0)

REXML::Child オブジェクトを生成します。

...REXML::Child オブジェクトを生成します。

parent で親ノードを指定します。
親ノードへの追加は行わないため、オブジェクト生成後に親に
適切に設定する必要があります。

通常、このメソッドは直接は使いません。継承先の...

REXML::Document.new(source = nil, context = {}) -> REXML::Document (54307.0)

Document オブジェクトを生成します。

...Document オブジェクトを生成します。

source には String、IO、REXML::Document のいずかが
指定できます。 REXML::Document を指定すると
コンテキストと要素、属性が複製されます。
文字列の場合はそれを XML と見なしてパースします。...
...
また、すべての要素で空白を考慮して欲しい場合には
:all を指定します。
デフォルト値は :all です。
REXML
::Element#whitespace も参照してください。
: :compress_whitespace
空白を無視して欲しい要素の名前の集合を文字列の...
...ect_whitespace での指定を上書きします。
すべての要素で空白を無視して欲しい場合には
:all を指定します。
REXML
::Element#whitespace も参照してください。
: :ignore_whitespace_nodes
空白のみからなるノードを無視して欲しい要素...

絞り込み条件を変える

REXML::ElementDecl.new(src) -> REXML::ElementDecl (54307.0)

新たな要素宣言オブジェクトを作ります。

新たな要素宣言オブジェクトを作ります。

@param src 要素宣言文字列

REXML::ExternalEntity.new(src) -> REXML::ExternalEntity (54307.0)

新たな ExternalEntity オブジェクトを生成します。

新たな ExternalEntity オブジェクトを生成します。

@param src 宣言文字列

REXML::Formatters::Default.new(ie_hack=false) -> REXML::Formatter::Default (54307.0)

フォーマッタオブジェクトを生成して返します。

フォーマッタオブジェクトを生成して返します。

このフォーマッタによる出力は基本的にテキストの空白や改行を変化させません。

ie_hack に真を渡すと、空のタグを閉じる前で空白を挿入します。
これは特定のバージョンのIEのXMLパーサのバグを避けるための機能です。

@param ie_hack 空のタグを閉じる所にスペースを入れるかどうかを指定します

REXML::Formatters::Pretty.new(indentation=2, ie_hack=false) -> REXML::Formatter::Pretty (54307.0)

フォーマッタオブジェクトを生成して返します。

フォーマッタオブジェクトを生成して返します。

このフォーマッタによる出力はテキストの空白や改行を調整し、
適切なインデントを挿入して読みやすいXMLを出力します。

indentation でインデント幅を(空白の数で)指定します。

ie_hack に真を渡すと、空のタグを閉じる前で空白を挿入します。
これは特定のバージョンのIEのXMLパーサのバグを避けるための機能です。

@param indentation 出力のインデント幅
@param ie_hack 空のタグを閉じる所にスペースを入れるかどうか

REXML::Formatters::Transitive.new(indentation=2, ie_hack=false) -> REXML::Formatter::Transitive (54307.0)

フォーマッタオブジェクトを生成して返します。

フォーマッタオブジェクトを生成して返します。

このフォーマッタによる出力は基本的にテキストの空白や改行を変化させないと
いう制約のもと、出力を整形します。

indentation でインデント幅を指定できます。

ie_hack に真を渡すと、空のタグを閉じる前で空白を挿入します。
これは特定のバージョンのIEのXMLパーサのバグを避けるための機能です。

@param indentation インデント幅
@param ie_hack 空のタグを閉じる所にスペースを入れるかどうかを指定します

絞り込み条件を変える

REXML::Instruction.new(target, content = nil) -> REXML::Instruction (54307.0)

新たな Instruction オブジェクトを生成します。

新たな Instruction オブジェクトを生成します。

@param target ターゲット
@param content 内容

REXML::NotationDecl.new(name, middle, pub, sys) -> REXML::NotationDecl (54307.0)

NotationDecl オブジェクトを生成します。

NotationDecl オブジェクトを生成します。

@param name 記法名(文字列)
@param middle 種別("PUBLIC" もしくは "SYSTEM")
@param pub 公開識別子(文字列)
@param sys URI(文字列)

REXML::Parent.new(parent = nil) -> REXML::Parent (54307.0)

REXML::Parent オブジェクトを生成します。

...REXML::Parent オブジェクトを生成します。

子ノード列は空列に初期化されます。

parent で親ノードを指定します。
親ノードへの追加は行わないため、オブジェクト生成後に親に
適切に設定する必要があります。

通常、この...

REXML::Parsers::PullParser.new(stream) -> REXML::Parsers::PullParser (54307.0)

新たな PullParser オブジェクトを生成して返します。

新たな PullParser オブジェクトを生成して返します。

@param source 入力(文字列、IO、IO互換オブジェクト(StringIOなど))

REXML::Parsers::SAX2Parser.new(source) -> REXML::Parsers::SAX2Parser (54307.0)

SAX2 パーサオブジェクトを生成します。

SAX2 パーサオブジェクトを生成します。

@param source 入力(文字列、IO、IO互換オブジェクト(StringIOなど))

絞り込み条件を変える

REXML::Parsers::StreamParser.new(source, listener) -> REXML::Parsers::StreamParser (54307.0)

ストリームパーサオブジェクトを生成します。

ストリームパーサオブジェクトを生成します。

@param source 入力(文字列、IO、IO互換オブジェクト(StringIOなど))
@param listener コールバックオブジェクト

REXML::Parsers::UltraLightParser.new(stream) -> REXML::Parsers::UltraLightParser (54307.0)

パーサオブジェクトを返します。

パーサオブジェクトを返します。

@param stream 入力(文字列、IO、IO互換オブジェクト(StringIOなど))

REXML::XMLDecl.new(version = REXML::XMLDecl::DEFAULT_VERSION, encoding = nil, standalone = nil) (54307.0)

新たな XMLDecl オブジェクトを生成して返します。

新たな XMLDecl オブジェクトを生成して返します。

version 以外は省略可能です。

@param version バージョン(文字列)
@param encoding エンコーディング(文字列 or nil)
@param standalone スタンドアロン文章かどうか("yes", "no", nil)

REXML::Formatters::Default (112.0)

XMLドキュメントを(文字列として)出力するクラスです。

...列として)出力するクラスです。

REXML
::Formatters::Pretty と
異なりテキストの改行や空白を修正せずにそのまま出力します。

//emlist[][ruby]{
require 'rexml/document'
require 'rexml/formatters/default'
doc = REXML::Document.new <<EOS
<root>
<children>
<grand...
...ren>
</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
# => "<children>\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::Elements#[]=(index, element) (76.0)

集合に要素 element を追加/更新します。

...@param element 要素(REXML::Elementオブジェクト)

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new '<a/>'
doc.root.elements[10] = REXML::Element.new('b')
doc.root.to_s # => "<a><b/></a>"
doc.root.elements[1] # => <b/>
doc.root.elements[1] = REXML::Element.new('c')
doc.roo...
...t.to_s # => "<a><c/></a>"
doc.root.elements['c'] = REXML::Element.new('d')
doc.root.to_s # => "<a><d/></a>"
//}...

絞り込み条件を変える

REXML::Formatters::Transitive (76.0)

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

...結果になるでしょう。

//emlist[][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
transit...
...>> <root
# >> ><children
# >> >
# >> <grandchildren foo='bar'
# >> />
# >> </children
# >> ></root
# >> >

output = StringIO.new
transitive_formatter.write(REXML::XPath.first(doc, "/root/children"), output)
output.string
# => "<children\n>\n<grandchildren foo='bar'\n />\n</children\n>"
//}...

REXML::Child#next_sibling=(other) (58.0)

other を self の次の隣接ノードとします。

...ther を挿入します。

@param other 挿入するノード

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

a = REXML::Element.new("a")
b = a.add_element("b")
c = REXML::Element.new("c")
b.next_sibling = c
d = REXML::Element.new("d")
b.previous_sibling = d

p a.to_s # => "<a><d/><b/><c/></a>"
//}...

REXML::Child#previous_sibling=(other) (58.0)

other を self の前の隣接ノードとします。

...other を挿入します。

@param other 挿入するノード

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

a = REXML::Element.new("a")
b = a.add_element("b")
c = REXML::Element.new("c")
b.next_sibling = c
d = REXML::Element.new("d")
b.previous_sibling = d

p a.to_s # => "<a><d/><b/><c/></a>"
//}...

REXML::Element#add_element(element, attrs = nil) -> Element (58.0)

子要素を追加します。

...子要素を追加します。

element として追加する要素を指定します。
REXML
::Element オブジェクトもしくは文字列を指定します。

element として REXML::Element オブジェクトを指定した場合、それが追加されます。
文字列を指定した場...
...た要素です。

@param element 追加する要素
@param attrs 追加する要素に設定する属性

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new('<a/>')
el = doc.root.add_element 'my-tag' # => <my-tag/>
doc.root.to_s # => "<a><my-tag/></a>"
el = doc.root.add_element '...
...'val1' attr2='val2'/>
doc.root.to_s # => "<a><my-tag/><my-tag attr1='val1' attr2='val2'/></a>"
el = REXML::Element.new 'my-tag'
doc.root.add_element el # => <my-tag/>
doc.root.to_s # => "<a><my-tag/><my-tag attr1='val1' attr2='val2'/><my-tag/></a>"
//}

@see REXML::Elements#add, REXML::Element.new...

REXML::Elements#<<(element = nil) -> REXML::Element (58.0)

要素 element を追加します。

...要素 element を追加します。

element には文字列もしくは REXML::Element オブジェクトを
指定します。文字列を指定した場合には REXML::Element.new(element)
で生成される要素を追加します。

element を省略した場合は、空の要素が追加...
...ます。

追加された要素が返されます。

@param element 追加する要素

//emlist[][ruby]{
require 'rexml/document'
a = REXML::Element.new('a')
a.elements.add(REXML::Element.new('b')) # => <b/>
a.to_s # => "<a><b/></a>"
a.elements.add('c') # => <c/>
a.to_s # => "<a><b/><c/></a>"
//...

絞り込み条件を変える

REXML::Elements#add(element = nil) -> REXML::Element (58.0)

要素 element を追加します。

...要素 element を追加します。

element には文字列もしくは REXML::Element オブジェクトを
指定します。文字列を指定した場合には REXML::Element.new(element)
で生成される要素を追加します。

element を省略した場合は、空の要素が追加...
...ます。

追加された要素が返されます。

@param element 追加する要素

//emlist[][ruby]{
require 'rexml/document'
a = REXML::Element.new('a')
a.elements.add(REXML::Element.new('b')) # => <b/>
a.to_s # => "<a><b/></a>"
a.elements.add('c') # => <c/>
a.to_s # => "<a><b/><c/></a>"
//...

REXML::Formatters::Pretty (58.0)

XMLドキュメントを(文字列として)見た目良く出力するクラスです。

...た目良く出力するクラスです。

REXML
::Formatters::Default と
異なり見た目のためテキストの改行や空白を修正して出力します。

//emlist[][ruby]{
require 'rexml/document'
require 'rexml/formatters/pretty'
doc = REXML::Document.new <<EOS
<root>
<children>
<gra...
...ndchildren 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::XMLDecl (58.0)

XML 宣言を表すクラス。

...XML 宣言を表すクラス。

文書から XML 宣言を取り出すには REXML::Document#xml_decl を使います。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<e />
EOS

xml_decl = doc.xml_decl
xml_decl....
...e 'rexml/document'
doc = REXML::Document.new(<<EOS)
<e />
EOS

xml_decl = doc.xml_decl
xml_decl.version # => "1.0"
xml_decl.encoding # => "UTF-8"
xml_decl.standalone # => nil
xml_decl.writethis # => false
//}

//emlist[XML 宣言が encoding 属性を持たない場合の例][ruby]{
require 'rexml/d...
...ocument'
doc = REXML::Document.new(<<EOS)
<?xml version="1.0" ?>
<e />
EOS

xml_decl = doc.xml_decl
xml_decl.version # => "1.0"
xml_decl.encoding # => "UTF-8"
xml_decl.standalone # => nil
xml_decl.writethis # => true
//}...

REXML::Parsers::SAX2Parser#parse -> () (52.0)

REXML::Parsers::SAX2Parser.new で指定した XML を パースし、その結果によって REXML::Parsers::SAX2Parser#listen で 指定したコールバックを呼び出します。

...REXML::Parsers::SAX2Parser.new で指定した XML を
パースし、その結果によって REXML::Parsers::SAX2Parser#listen で
指定したコールバックを呼び出します。

@raise REXML::ParseException XML文書のパースに失敗した場合に発生します
@raise REXML::Undefin...

REXML::Parsers::UltraLightParser#rewind -> () (52.0)

REXML::Parsers::UltraLightParser.new で指定した stream を rewind してもう一度パースできる状態にします。

...REXML::Parsers::UltraLightParser.new で指定した stream を
rewind してもう一度パースできる状態にします。...

絞り込み条件を変える

REXML::XMLDecl::DEFAULT_VERSION -> String (52.0)

REXML::XMLDecl.new や REXML::XMLDecl.default で の使われるデフォルトのXMLバージョン。

...REXML::XMLDecl.new や REXML::XMLDecl.default で
の使われるデフォルトのXMLバージョン。...

REXML::Attribute#prefix -> String (40.0)

属性の名前空間を返します。

...//emlist[][ruby]{
require 'rexml/document'
e = REXML::Element.new( "elns:myelement" )
e.add_attribute( "nsa:a", "aval" )
e.add_attribute( "b", "bval" )
p e.attributes.get_attribute( "a" ).prefix # -> "nsa"
p e.attributes.get_attribute( "b" ).prefix # -> "elns"
a = REXML::Attribute.new( "x", "y"...

REXML::DocType#external_id -> String | nil (40.0)

DTD が外部サブセットを用いている場合は "SYSTEM", "PUBLIC" の いずれかの文字列を返します。

...t[][ruby]{
require 'rexml/document'
doctype = REXML::Document.new(<<EOS).doctype
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
EOS
doctype.name # => "html"
doctype.external_id # => "PUBLIC"

doctype = REXML::Document.new(<<EO...

REXML::DocType#public -> String | nil (40.0)

DTD の公開識別子を返します。

...DTD が公開識別子による外部サブセットを含んでいない場合は nil を返します。

//emlist[][ruby]{
require 'rexml/document'
doctype = REXML::Document.new(<<EOS).doctype
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtm...
...l1-strict.dtd">
EOS
doctype.system # => "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype.public # => "-//W3C//DTD XHTML 1.0 Strict//EN"

doctype = REXML::Document.new(<<EOS).doctype
<!DOCTYPE root SYSTEM "foobar">
EOS
doctype.system # => "foobar"
doctype.public # => nil
//}...

REXML::DocType#system -> String | nil (40.0)

DTD のシステム識別子を返します。

...子を返します。

DTD が外部サブセットを含んでいない場合は nil を返します。

//emlist[][ruby]{
require 'rexml/document'
doctype = REXML::Document.new(<<EOS).doctype
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1...
...-strict.dtd">
EOS
doctype.system # => "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype.public # => "-//W3C//DTD XHTML 1.0 Strict//EN"

doctype = REXML::Document.new(<<EOS).doctype
<!DOCTYPE root SYSTEM "foobar">
EOS
doctype.system # => "foobar"
doctype.public # => nil
//}...

絞り込み条件を変える

REXML::Element#add_attribute(attr) -> () (40.0)

要素の属性を追加します。 同じ名前の属性がすでにある場合はその属性を新しい 属性で置き換えます。

...で渡す方法と REXML::Attribute オブジェクトを
渡す方法です。

文字列2つで指定する場合、属性値は unnormalized な文字列を渡す必要があります。

@param key 属性名(文字列)
@param value 属性値(文字列)
@param attr 属性(REXML::Attribute オブ...
...ジェクト)

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new("<e/>")
doc.root.add_attribute("a", "b"); doc.root # => <e a='b'/>
doc.root.add_attribute("x:a", "c"); doc.root # => <e a='b' x:a='c'/>
doc.root.add_attribute(REXML::Attribute.new("b", "d"))
doc.root # => <e a='b' x:...

REXML::Element#add_attribute(key, value) -> () (40.0)

要素の属性を追加します。 同じ名前の属性がすでにある場合はその属性を新しい 属性で置き換えます。

...で渡す方法と REXML::Attribute オブジェクトを
渡す方法です。

文字列2つで指定する場合、属性値は unnormalized な文字列を渡す必要があります。

@param key 属性名(文字列)
@param value 属性値(文字列)
@param attr 属性(REXML::Attribute オブ...
...ジェクト)

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new("<e/>")
doc.root.add_attribute("a", "b"); doc.root # => <e a='b'/>
doc.root.add_attribute("x:a", "c"); doc.root # => <e a='b' x:a='c'/>
doc.root.add_attribute(REXML::Attribute.new("b", "d"))
doc.root # => <e a='b' x:...

REXML::Element#add_attributes(attrs) -> () (40.0)

要素の属性を複数追加します。 同じ名前の属性がすでにある場合はその属性を新しい 属性で置き換えます。

...属性の属性名と属性値の対の集合(Array or Hash)

//emlist[][ruby]{
require 'rexml/document'
e = REXML::Element.new("e")
e.add_attributes({"a" => "b", "c" => "d"})
e # => <e a='b' c='d'/>
e = REXML::Element.new("e")
e.add_attributes([["a", "b"], ["c", "d"]])
e # => <e a='b' c='d'/>
//}...

REXML::Element#text=(text) (40.0)

「先頭の」テキストノードを text で置き換えます。

...ノードが追加されます。

text には文字列、REXML::Text、nil のいずれかが指定できます。
REXML
::Text オブジェクトを指定した場合には、それが設定され、
文字列を指定した場合には
REXML
::Text.new(text, whitespace(), nil, raw())
で生成さ...
...初のテキストノードが削除されます。

@param text 置き換え後のテキスト(文字列、REXML::Text, nil(削除))

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new('<a><b/></a>')
doc.to_s # => "<a><b/></a>"
doc.root.text = "Foo"; doc.to_s # => "<a><b/>Foo</a>"...

REXML::Element#xpath -> String (40.0)

文書上の対象の要素にのみマッチする xpath 文字列を返します。

...る xpath 文字列を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new('<a><b/><c/></a>')
c = doc.root.elements[2] # <a> .. </a> の中の <c/> 要素
c # => <c/>
c.xpath # => "/a/c"
doc = REXML::Document.new('<a><b/><b/></a>')
b = doc.root.elements[2] # <a> .. <...

絞り込み条件を変える

REXML::Elements#[](index, name = nil) -> REXML::Element | nil (40.0)

index が指し示している要素を返します。

...(文字列)

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new '<a><b/><c id="1"/><c id="2"/><d/></a>'
doc.root.elements[1] # => <b/>
doc.root.elements['c'] # => <c id='1'/>
doc.root.elements[2,'c'] # => <c id='2'/>

doc = REXML::Document.new '<a><b><c /><a id="1"/></b...

REXML::StreamListener#entitydecl(content) -> () (40.0)

DTDの実体宣言をパースしたときに呼び出されるコールバックメソッドです。

...き方によって content に渡されるデータの形式が異なります。

//emlist[][ruby]{
require 'rexml/parsers/baseparser'
require 'rexml/parsers/streamparser'
require 'rexml/streamlistener'
xml = <<EOS
<!DOCTYPE root [
<!ENTITY % YN '"Yes"'>
<!ENTITY % YN 'Yes'>
<!ENTITY WhatHeSaid "He...
...ch.xml">
<!ENTITY hatch-pic SYSTEM "../grafix/OpenHatch.gif" NDATA gif>
]>
<root />
EOS

class Listener
include REXML::StreamListener
def entitydecl(content); p content; end
end
REXML
::Parsers::StreamParser.new(xml, Listener.new).parse
# >> ["YN", "\"Yes\"", "%"]
# >> ["YN", "Yes", "%"]
# >> ["W...

REXML::Text#to_s -> String (40.0)

テキストの内容を正規化(すべての実体をエスケープ)された状態で返します。

...まり返り値は XML のテキストとして妥当です。

結果は REXML::Text.new で指定した entity_filter を反映しています。

@see REXML::Text#value

//emlist[][ruby]{
require 'rexml/document'
t = REXML::Text.new("< & foobar", false, nil, false)
t.to_s # => "&lt; &amp; foobar"...

REXML::ParseException (25.0)

XML のパースに失敗したときに生じる例外です。

...XML のパースに失敗したときに生じる例外です。

//emlist[][ruby]{
require 'rexml/document'
begin
REXML
::Document.new("<a>foo\n</b></a> ")
rescue REXML::ParseException => ex
ex.position # => 16
ex.line # => 2
ex.context # => [16, 2, 2]
end
//}...

REXML::Attribute#namespace(arg = nil) -> String | nil (22.0)

属性の名前空間の URI を返します。

...でなく、arg という名前空間
の URI が返されます。
通常は省略します。

//emlist[][ruby]{
require 'rexml/document'
e = REXML::Element.new("el")
e.add_attribute("xmlns:ns", "http://www.example.com/ns")
e.add_attribute("ns:r", "rval")
p e.attributes.get_attribute...

絞り込み条件を変える

REXML::Attribute#to_string -> String (22.0)

"name='value'" という形式の文字列を返します。

..."name='value'" という形式の文字列を返します。

//emlist[][ruby]{
require 'rexml/document'
e = REXML::Element.new("el")
e.add_attribute("ns:r", "rval")
p e.attributes.get_attribute("r").to_string # => "ns:r='rval'"
//}...

REXML::Attributes#[](name) -> String | nil (22.0)

属性名nameの属性値を返します。

...はなく REXML::Attribute オブジェクトが必要な場合は
REXML
::Attributes#get_attribute を使ってください。

nameという属性名の属性がない場合は nil を返します。

@param name 属性名(文字列)

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

doc = REXML::Documen...

REXML::Attributes#[]=(name, value) (22.0)

指定した属性を更新します。

...名前の属性がある場合は上書きされ、
そうでない場合は属性が追加されます。

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

doc = REXML::Document.new(<<-EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a foo:att='1' bar:att='2' at...
...t='&lt;'/>
</root>
EOS
a = doc.get_elements("/root/a").first

a.attributes["att"] = "9"
a.attributes["foo:attt"] = "8"
a # => <a foo:att='1' bar:att='2' att='9' foo:attt='8'/>
//}

@see REXML::Attributes#add...

REXML::Attributes#delete(attribute) -> REXML::Element (22.0)

指定した属性を取り除きます。

...列もしくは REXML::Attribute オブジェクトを指定します

self が属する要素(REXML::Element)を返します。

@param attribute 取り除く属性(文字列もしくは REXML::Attribute オブジェクト)

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

doc = REXML::Document.new(<<-E...

REXML::Attributes#delete_all(name) -> [REXML::Attribute] (22.0)

name という名前を持つ属性をすべて削除します。

...除します。

削除された属性を配列で返します。

@param name 削除する属性の名前

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

doc = REXML::Document.new(<<-EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a foo:att='1' bar:att='2' at...

絞り込み条件を変える

REXML::Attributes#each {|name, value| ... } -> () (22.0)

各属性の名前と値に対しブロックを呼び出します。

...属性の名前と値に対しブロックを呼び出します。

名前には expanded_name(REXML::Namespace#exapnded_name)が
渡されます。

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

doc = REXML::Document.new(<<EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example....

REXML::Attributes#each_attribute {|attribute| ... } -> () (22.0)

各属性に対しブロックを呼び出します。

...各属性に対しブロックを呼び出します。

個々の属性は REXML::Attribute オブジェクトで渡されます。

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

doc = REXML::Document.new(<<EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a fo...

REXML::Attributes#get_attribute(name) -> Attribute | nil (22.0)

name という名前の属性を取得します。

...という名前を持つ属性がない場合は nil を返します。

@param name 属性名(文字列)
@see REXML::Attributes#[]

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

doc = REXML::Document.new(<<-EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a...

REXML::Attributes#get_attribute_ns(namespace, name) -> REXML::Attribute | nil (22.0)

namespace と name で特定される属性を返します。

...ることができます。

@param namespace 名前空間(URI, 文字列)
@param name 属性名(文字列)

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

doc = REXML::Document.new(<<-EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a foo:att='1' bar:att='2' a...

REXML::Attributes#length -> Integer (22.0)

属性の個数を返します。

...属性の個数を返します。


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

doc = REXML::Document.new(<<EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a foo:att='1' bar:att='2' att='&lt;'/>
</root>
EOS
a = doc.get_elements("/root/a").first

p a.attribu...

絞り込み条件を変える

REXML::Attributes#namespaces -> { String => String } (22.0)

self の中で宣言されている名前空間の集合を返します。

...ます。

返り値は名前空間の prefix をキーとし、URI を値とする
Hash を返します。

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

doc = REXML::Document.new(<<EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a foo:att='1' bar:att='2' at...

REXML::Attributes#prefixes -> [String] (22.0)

self の中で宣言されている prefix の集合を 文字列の配列で返します。

...ます。

self が属する要素より上位の要素で定義されているものは含みません。

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

doc = REXML::Document.new(<<EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a foo:att='1' bar:att='2' att...

REXML::Attributes#size -> Integer (22.0)

属性の個数を返します。

...属性の個数を返します。


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

doc = REXML::Document.new(<<EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a foo:att='1' bar:att='2' att='&lt;'/>
</root>
EOS
a = doc.get_elements("/root/a").first

p a.attribu...

REXML::Attributes#to_a -> [Attribute] (22.0)

属性の配列を返します。

...属性の配列を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new("<a x='1' y='2' z='3' />")
doc.root.attributes.to_a # => [x='1', y='2', z='3']
//}...

REXML::CData#to_s -> String (22.0)

テキスト文字列を返します。

...テキスト文字列を返します。

@see REXML::Text#value, REXML::Text#to_s

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<root><![CDATA[foobar baz]]></root>
EOS
doc.root[0].class # => REXML::CData
doc.root[0].value # => "foobar baz"
//}...

絞り込み条件を変える

REXML::CData#value -> String (22.0)

テキスト文字列を返します。

...テキスト文字列を返します。

@see REXML::Text#value, REXML::Text#to_s

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<root><![CDATA[foobar baz]]></root>
EOS
doc.root[0].class # => REXML::CData
doc.root[0].value # => "foobar baz"
//}...

REXML::Comment (22.0)

XML コメントを表すクラス。

...XML コメントを表すクラス。

コメントとは <!-- と --> で挟まれたテキストです。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<!-- xx -->
<root>
<!-- yy -->
text
<!-- zz -->
</root>
EOS

doc[0].string # => " xx "
doc.root[1].string # => " yy...

REXML::DocType#attribute_of(element, attribute) -> String | nil (22.0)

DTD 内の属性リスト宣言で、 element という名前の要素の attribute という 名前の属性のデフォルト値を返します。

...合は nil を返します。

@param element 要素名(文字列)
@param attribute 属性名(文字列)

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

doctype = REXML::Document.new(<<EOS).doctype
<!DOCTYPE books [
<!ELEMENT book (comment)>
<!ELEMENT comment (#PCDATA)>
<!ATTLIST book
author...

REXML::DocType#attributes_of(element) -> [REXML::Attribute] (22.0)

DTD 内の属性リスト宣言で、 element という名前の要素に対し宣言されている 属性の名前とデフォルト値を REXML::Attribute の配列で返します。

...デフォルト値を REXML::Attribute の配列で返します。

名前とデフォルト値のペアは、各 Attribute オブジェクトの
REXML
::Attribute#name と
REXML
::Attribute#value で表現されます。

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

doctype = REXML::Document.new(<<EOS...

REXML::DocType#entities -> { String => REXML::Entity } (22.0)

DTD で宣言されている実体の集合を Hash で返します。

...体参照名をキーとし、対応する REXML::Entity オブジェクト
を値とするハッシュテーブルです。

これには、XML のデフォルトの実体(gt, lt, quot, apos)も含まれています。

//emlist[][ruby]{
doctype = REXML::Document.new(<<EOS).doctype
<!DOCTYPE foo [...
...<!ENTITY bar "barbarbarbar">
]>
EOS

p doctype.entities # => { "gt" => #<REXML::Entity: ...>,
# "lt" => #<REXML::Entity: ...>, ... }
p doctype.entities["bar"].to_s # => "<!ENTITY bar \"barbarbarbar\">"
p doctype.entities["gt"].to_s # => "<!ENTITY gt \">\">"
//}...

絞り込み条件を変える

REXML::DocType#entity(name) -> String | nil (22.0)

name という実体参照名を持つ実体を文字列で返します。

...れる文字列は非正規化(REXML::Entity#unnormalized 参照)
された文字列が返されます。

name という名前を持つ実体が存在しない場合には nil を返します。

@param name 実体参照名(文字列)

//emlist[][ruby]{
doctype = REXML::Document.new(<<EOS).doctype...

REXML::DocType#name -> String (22.0)

ルート要素名を返します。

...ルート要素名を返します。

//emlist[][ruby]{
document = REXML::Document.new(<<EOS)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
EOS
doctype = document.doctype
p doctype.name # => "html"
//}...

REXML::DocType#write(output, indent = 0, transitive = false, ie_hack = false) -> () (22.0)

output に DTD を出力します。

...output に DTD を出力します。

このメソッドは deprecated です。REXML::Formatter で
出力してください。

@param output 出力先の IO オブジェクト
@param indent インデントの深さ。指定しないでください。
@param transitive 無視されます。指定...
...しないでください。
@param ie_hack 無視されます。指定しないでください。

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

doctype = REXML::Document.new(<<EOS).doctype
<!DOCTYPE books [
<!ELEMENT book (comment)>
<!ELEMENT comment (#PCDATA)>
<!ATTLIST book
author CDATA #...

REXML::Document#clone -> REXML::Document (22.0)

self を複製します。

...self を複製します。

REXML
::Document.new(self) と同じです。...

REXML::Document#encoding -> String (22.0)

XML 宣言に含まれている XML 文書のエンコーディングを返します。

...を返します。

文書が XML 宣言を持たない場合はデフォルトの値
(REXML::XMLDecl.defaultで宣言されているもの)を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<e />
EO...

絞り込み条件を変える

REXML::Document#stand_alone? -> String (22.0)

XML 宣言の standalone の値を文字列で返します。

...XML 宣言の standalone の値を文字列で返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<e />
EOS
doc.stand_alone? # => "yes"
//}...

REXML::Document#version -> String (22.0)

XML 宣言に含まれている XML 文書のバージョンを返します。

...を返します。

文書が XML 宣言を持たない場合はデフォルトの値
(REXML::XMLDecl.defaultで宣言されているもの)を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<e />
EO...

REXML::Document.parse_stream(source, listener) -> () (22.0)

XML文書を source から読み込み、パースした結果を listener にコールバックで伝えます。

...arser.new( source, listener ).parse
と同じ挙動をします。

コールバックの詳しい仕組みなどについては REXML::Parsers::StreamParser
および REXML::StreamListener を参照してください。

@param source 入力(文字列、IO、IO互換オブジェクト(StringIOな...

REXML::Element#add_namespace(prefix, uri) -> self (22.0)

名前空間を要素に追加します。

...合はそれが上書きされます。

@param prefix 名前空間の prefix
@param uri 名前空間の uri

//emlist[][ruby]{
require 'rexml/document'
a = REXML::Element.new("a")
a.add_namespace("xmlns:foo", "bar" )
a.add_namespace("foo", "bar") # 上と同じ意味
a.add_namespace("twiddle")
a.t...

REXML::Element#add_namespace(uri) (22.0)

名前空間を要素に追加します。

...合はそれが上書きされます。

@param prefix 名前空間の prefix
@param uri 名前空間の uri

//emlist[][ruby]{
require 'rexml/document'
a = REXML::Element.new("a")
a.add_namespace("xmlns:foo", "bar" )
a.add_namespace("foo", "bar") # 上と同じ意味
a.add_namespace("twiddle")
a.t...

絞り込み条件を変える

REXML::Element#attribute(name, namespace = nil) -> REXML::Attribute | nil (22.0)

name で指定される属性を返します。

...name で指定される属性を返します。

属性は REXML::Attribute オブジェクトの形で返します。

name は "foo:bar" のように prefix を指定することができます。

namespace で名前空間の URI を指定することで、その名前空間内で
name という...
...は nil を返します。

@param name 属性名(文字列)
@param namespace 名前空間のURI(文字列)
//emlist[][ruby]{
require 'rexml/document'

doc = REXML::Document.new(<<-EOS)
<root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<a foo:att='1' bar:att='2' at...

REXML::Element#context -> {Symbol => object} | nil (22.0)

要素の「コンテキスト」を Hash で返します。

...要素の「コンテキスト」を Hash で返します。

コンテキストとは text node (REXML::Text) での特別な文字、特に空白について
の取り扱いについての設定です。
以下の Symbol をハッシュのキーとして使います。

: :respect_whitespace...
...
また、すべての要素で空白を考慮して欲しい場合には
:all を指定します。
デフォルト値は :all です。
REXML
::Element#whitespace も参照してください。
: :compress_whitespace
空白を無視して欲しい要素の名前の集合を文字列の...
...ect_whitespace での指定を上書きします。
すべての要素で空白を無視して欲しい場合には
:all を指定します。
REXML
::Element#whitespace も参照してください。
: :ignore_whitespace_nodes
空白のみからなるノードを無視して欲しい要素...

REXML::Element#context=(value) (22.0)

要素の「コンテキスト」を Hash で設定します。

...要素の「コンテキスト」を Hash で設定します。

コンテキストとは、 text node (REXML::Text) での特別な文字、特に空白について
の取り扱いについての設定です。
以下の Symbol をハッシュのキーとして使います。

: :respect_whitespac...
...
また、すべての要素で空白を考慮して欲しい場合には
:all を指定します。
デフォルト値は :all です。
REXML
::Element#whitespace も参照してください。
: :compress_whitespace
空白を無視して欲しい要素の名前の集合を文字列の...
...ect_whitespace での指定を上書きします。
すべての要素で空白を無視して欲しい場合には
:all を指定します。
REXML
::Element#whitespace も参照してください。
: :ignore_whitespace_nodes
空白のみからなるノードを無視して欲しい要素...

REXML::Element#delete_attribute(key) -> REXML::Attribute | nil (22.0)

要素から key という属性名の属性を削除します。

...合は削除されずに、nil を返します。

@param key 削除する要素(文字列(属性名) or REXML::Attributeオブジェクト)

//emlist[][ruby]{
require 'rexml/document'
e = REXML::Element.new("E")
e.add_attribute("x", "foo"); e # => <E x='foo'/>
e.add_attribute("y:x", "bar"); e # =>...

REXML::Element#delete_element(element) -> REXML::Element (22.0)

子要素を削除します。

...子要素を削除します。

element で削除する要素を指定できます。整数、文字列、REXML::Element
オブジェクトのいずれかが指定できます。

REXML
::Element を指定すると、その要素が削除されます。
整数を指定すると、element 番目の...
...素がマッチする場合はそのうち1つが削除されます。

@param element 削除する要素
@see REXML::Elements#delete

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new '<a><b/><c/><c id="1"/><d/><c/></a>'
doc.delete_element("/a/b")
doc.to_s # => "<a><c/><c id='1'/...

絞り込み条件を変える

REXML::Element#delete_namespace(namespace = "xmlns") -> self (22.0)

名前空間を要素から削除します。

...はデフォルトの名前空間を削除します。

@param namespace 削除する名前空間の prefix

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new "<a xmlns:foo='bar' xmlns='twiddle'/>"
doc.root.delete_namespace
doc.to_s # => "<a xmlns:foo='bar'/>"
doc.root.delete_name...

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

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

...字列)
@param max ブロック呼出の対象とする子要素の最大個数
@param name xpath文字列

//emlist[][ruby]{
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'/>
# >>...

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

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

...字列)
@param max ブロック呼出の対象とする子要素の最大個数
@param name xpath文字列

//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> ....

REXML::Element#get_text(path = nil) -> REXML::Text | nil (22.0)

先頭のテキスト子ノードを返します。

...ます。
REXML
::Text#value も参照してください。

path を渡した場合は、その XPath 文字列で指定される
テキストノードの文字列を返します。

テキストノードがない場合には nil を返します。

@param path XPath文字列
@see REXML::Element#tex...
...t

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new "<p>some text <b>this is bold!</b> more text</p>"
# doc.root (<p> ... </p>) は2つのテキストノード("some text " と " more text"
# を持っているが、前者を返す
doc.root.get_text.value # => "some text "
//}...

REXML::Element#has_elements? -> bool (22.0)

self が一つでも子要素を持つならば true を返します。

...self が一つでも子要素を持つならば true を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new("<a><b/><c>Text</c></a>")
doc.root.has_elements? # => true
doc.elements["/a/b"].has_elements? # => false
# /a/c はテキストノードしか...

絞り込み条件を変える

REXML::Element#namespace(prefix=nil) -> String (22.0)

self の文脈で prefix が指している名前空間の URI を返します。

...ます。

prefix で指示される名前空間の宣言が存在しない場合は nil を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new("<a xmlns='1' xmlns:y='2'><b/><c xmlns:z='3'/><y:d /></a>")
b = doc.elements['//b']
b.namespace # => "1"
b.namespace(...

REXML::Element#namespaces -> {String => String} (22.0)

self の文脈で定義されている名前空間の情報を返します。

...義されている名前空間を、{ prefix => 識別子 }
というハッシュテーブルで返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new("<a xmlns:x='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
doc.elements['//b'].namespaces # => {"x"=>"1", "y"=>"2"}
//}...

REXML::Element#next_element -> Element | nil (22.0)

次の兄弟要素を返します。

...次の兄弟要素を返します。

次の要素が存在しない場合は nil を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new '<a><b/>text<c/></a>'
doc.root.elements['b'].next_element # => <c/>
doc.root.elements['c'].next_element # => nil
//}...

REXML::Element#prefixes -> [String] (22.0)

self の文脈で定義されている prefix を文字列の配列を返します。

...字列の配列を返します。

対象の要素とその外側の要素で定義されている prefix を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new("<a xmlns:x='1' xmlns:y='2'><b/><c xmlns:z='3'/></a>")
doc.elements['//b'].prefixes # => ["x", "y"]
//}...

REXML::Element#root -> REXML::Element (22.0)

self が属する文書のルート要素を返します。

...self が属する文書のルート要素を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<root>
<children>
<grandchildren />
</children>
</root>
EOS

children = doc.get_elements("/root/children").first
children.name # => "children"
children.root.name...

絞り込み条件を変える

<< 1 2 > >>