るりまサーチ (Ruby 2.3.0)

最速Rubyリファレンスマニュアル検索!
73件ヒット [1-73件を表示] (0.035秒)

別のキーワード

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

検索結果

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

self を複製します。

...self を複製します。

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

REXML::Document#encoding -> String (63025.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 (63025.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 (63025.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#write(output = $stdout, indent = -1, transitive = false, ie_hack = false, encoding=nil) -> () (63025.0)

output に XML 文書を出力します。

...を含んでいなくとも
出力される XML はデフォルトの XML 宣言を含んでいるべきであるが、
REXML
は明示しない限り(つまりXML宣言を REXML::Document#add で
追加しない限り)
それをしない、ということである。XML-RPCのような利用法で...

絞り込み条件を変える

REXML::Document#write(output: $stdout, indent: -1, transitive: false, ie_hack: false, encoding: nil) -> () (63025.0)

output に XML 文書を出力します。

...を含んでいなくとも
出力される XML はデフォルトの XML 宣言を含んでいるべきであるが、
REXML
は明示しない限り(つまりXML宣言を REXML::Document#add で
追加しない限り)
それをしない、ということである。XML-RPCのような利用法で...

REXML::Document#<<(child) -> () (63007.0)

子ノードを追加します。

...子ノードを追加します。

追加できるものは
* XML宣言(REXML::XMLDecl)
* DTD(REXML::DocType)
* ルート要素
のいずれかです。...

REXML::Document#add(child) -> () (63007.0)

子ノードを追加します。

...子ノードを追加します。

追加できるものは
* XML宣言(REXML::XMLDecl)
* DTD(REXML::DocType)
* ルート要素
のいずれかです。...

REXML::Document#doctype -> REXML::DocType | nil (63007.0)

文書の DTD を返します。

文書の DTD を返します。

文書が DTD を持たない場合は nil を返します。

REXML::Document#expanded_name -> String (63007.0)

""(空文字列)を返します。

""(空文字列)を返します。

XMLの仕様上、このオブジェクトはexpanded name名前を持ちえません。

絞り込み条件を変える

REXML::Document#name -> String (63007.0)

""(空文字列)を返します。

""(空文字列)を返します。

XMLの仕様上、このオブジェクトはexpanded name名前を持ちえません。

REXML::Document#node_type -> Symbol (63007.0)

シンボル :document を返します。

シンボル :document を返します。

REXML::Document#root -> REXML::Element | nil (63007.0)

文書のルート要素を返します。

文書のルート要素を返します。

文書がルート要素を持たない場合は nil を返します。

REXML::Document#xml_decl -> REXML::XMLDecl | nil (63007.0)

文書の XML 宣言を返します。

文書の XML 宣言を返します。

文書が XML 宣言を持たない場合は nil を返します。

REXML::Element#root_node -> REXML::Document | REXML::Node (364.0)

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

...素が属する文書(REXML::Document) オブジェクトが
返されます。

その要素が属する REXML::Document オブジェクトが存在しない
場合は木構造上のルートノードが返されます。

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

絞り込み条件を変える

REXML::Child#document -> REXML::Document | nil (358.0)

そのノードが属する document (REXML::Document) を返します。

...そのノードが属する document (REXML::Document) を返します。

属する document が存在しない場合は nil を返します。...

REXML::Element#document -> REXML::Document | nil (358.0)

self が属する文書(REXML::Document)オブジェクトを返します。

...self が属する文書(REXML::Document)オブジェクトを返します。

属する文書がない場合には nil を返します。...

REXML::XMLDecl#dowrite -> () (55.0)

出力時(REXML::Document#write) に XML 宣言を省略しない よう指示します。

...出力時(REXML::Document#write) に XML 宣言を省略しない
よう指示します。

@see REXML::XMLDecl#nowrite, REXML::XMLDecl#writethis...

REXML::XMLDecl#nowrite -> () (55.0)

出力時(REXML::Document#write) に XML 宣言を省略する よう指示します。

...出力時(REXML::Document#write) に XML 宣言を省略する
よう指示します。

@see REXML::XMLDecl#dowrite, REXML::XMLDecl#writethis...

REXML::XMLDecl#writethis -> bool (55.0)

出力時(REXML::Document#write) に XML 宣言を出力する(省略しない) ならば真を返します。

...出力時(REXML::Document#write) に XML 宣言を出力する(省略しない)
ならば真を返します。

@see REXML::XMLDecl#dowrite, REXML::XMLDecl#nowrite...

絞り込み条件を変える

REXML::DocType#external_id -> String | nil (43.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 (43.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 (43.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#xpath -> String (43.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 (43.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::Text#doctype -> REXML::DocType | nil (43.0)

テキストノードが属する文書の DTD を返します。

...テキストノードが属する文書の DTD を返します。

そのような文書(REXML::Document)が存在しない、すなわち
テキストノードの親ノードを辿っても REXML::Document に到達しない、
場合には nil を返します。

@see REXML::DocType...

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

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

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

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

@param name 属性名(文字列)

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

doc = REXML::Documen...

REXML::Attributes#[]=(name, value) (25.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 (25.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] (25.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| ... } -> () (25.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| ... } -> () (25.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 (25.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 (25.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 (25.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 } (25.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] (25.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 (25.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] (25.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 (25.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 (25.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::DocType#attribute_of(element, attribute) -> String | nil (25.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] (25.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#context -> { Symbol => object } (25.0)

DTD が属する文書の「コンテキスト」を返します。

...DTD が属する文書の「コンテキスト」を返します。

具体的には親ノードである REXML::Document オブジェクトの
REXML
::Element#context を返します。

コンテキストの具体的な内容については REXML::Element#context を
参照してください。...

REXML::DocType#entities -> { String => REXML::Entity } (25.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 (25.0)

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

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

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

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

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

REXML::DocType#name -> String (25.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) -> () (25.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::Element#add_attribute(attr) -> () (25.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) -> () (25.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_element(element, attrs = nil) -> Element (25.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::Element#attribute(name, namespace = nil) -> REXML::Attribute | nil (25.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#delete_element(element) -> REXML::Element (25.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 (25.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| ... } -> () (25.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| ... } -> () (25.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 (25.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 (25.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 (25.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} (25.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 (25.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] (25.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 (25.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...

REXML::Element#text(path = nil) -> String | nil (25.0)

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

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

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

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

@param path XPath文字列
@see REXML::Element#get...
..._text

//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.text # => "some text "
//}...

REXML::Element#text=(text) (25.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::Elements#[]=(index, element) (25.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::Elements#delete(element) -> Element (25.0)

element で指定した子要素を取り除きます。

...element で指定した子要素を取り除きます。

element には、REXML::Element、整数、文字列が指定できます。
Element オブジェクトを指定した場合は、その子要素を取り除きます。
整数を指定した場合には element 番目の子要素を削除し...
...はない要素も取り除けることに注意してください。

@param element 削除する要素(REXML::Element, 整数, 文字列)

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

REXML::Elements#delete_all(xpath) -> [REXML::Element] (25.0)

xpath で指定した XPath 文字列にマッチする要素をすべて取り除きます。

...る要素をすべて取り除きます。

@param xpath 取り除く要素を指し示す XPath 文字列

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new('<a><c/><c/><c/><c/></a>')
doc.elements.delete_all("a/c") # => [<c/>, <c/>, <c/>, <c/>]
doc.to_s # =>...

REXML::Elements#each(xpath = nil) {|element| ... } -> [REXML::Elements] (25.0)

全ての子要素に対しブロックを呼び出します。

...呼び出します。

REXML
::XPath.each などとは異なり、要素以外の
テキストノードなどはすべて無視されることに注意してください。

@param xpath XPath文字列

//emlist[][ruby]{
require 'rexml/document'
require 'rexml/xpath'
doc = REXML::Document.new '<a><b/...
...ments.each('b') {|e|p e} #-> Yields b, b elements
# <b/>,<c/>,<d/>,<b/>,<c/>,<d/> がブロックに渡される
doc.root.elements.each('child::node()') {|e|p e}
# <b/>,<c/>,<d/>,"sean",<b/>,<c/>,<d/> がブロックに渡される
REXML
::XPath.each(doc.root, 'child::node()'){|node| p node }
//}...

REXML::Elements#size -> Integer (25.0)

保持している要素の個数を返します。

...保持している要素の個数を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new '<a>sean<b/>elliott<b/>russell<b/></a>'
# doc.root は3つの要素と3つのテキストノードを持つため、6を返す
doc.root.size # => 6
# そのうち要...

絞り込み条件を変える

REXML::Elements#to_a(xpath = nil) -> [REXML::Element] (25.0)

すべての子要素の配列を返します。

...要素の配列を返します。

REXML
::Elements#each と同様、REXML::XPath.match などと
異なり、要素以外の子ノードは無視されます。

@param xpath XPath文字列

//emlist[][ruby]{
require 'rexml/document'
require 'rexml/xpath'
doc = REXML::Document.new '<a>sean<b/>elliot...
...t<c/></a>'
doc.root.elements.to_a # => [<b/>, <c/>]
doc.root.elements.to_a("child::node()") # => [<b/>, <c/>]
REXML
::XPath.match(doc.root, "child::node()") # => ["sean", <b/>, "elliott", <c/>]
//}...

REXML::Instruction#content -> String | nil (25.0)

XML 処理命令の内容を返します。

...XML 処理命令の内容を返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/css" href="style.css"?>
<?foobar?>
<root />
EOS
doc[2] # => <?p-i xml-stylesheet ...?>
doc[2].target # => "xml-...

REXML::Instruction#target -> String (25.0)

XML 処理命令のターゲットを返します。

...XML 処理命令のターゲットを返します。

//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/css" href="style.css"?>
<root />
EOS
doc[2] # => <?p-i xml-stylesheet ...?>
doc[2].target # => "xml-st...