Class REXML::Document
In: rexml/document.rb

Represents a full XML document, including PIs, a doctype, etc. A Document has a single child that can be accessed by root().

Note that if you want to have an XML declaration written for a document you create, you must add one; REXML documents do not write a default declaration for you. See |DECLARATION| and |write|.

PI、DOCTYPE等を含む完全なXML文書を表現します。Documentは root()でアクセスすることができる唯一の子を持ちます。 もし、あなたが自分で作った文書の為に書かれたXML宣言を使いたいのな ら、あなたは、REXMLがあなたのためにデフォルトのXML宣言を書かないよ うに付け加えなければいけないことを注意して下さい。|DECLARATION|と |write|を見て下さい。

Methods
add    add_element    clone    doc_type    encoding    new    parse    parse_stream    root    stand_alone?    version    write    xml_decl   
Public Class methods
new( source = nil, context = {} )

Constructor

@param source if supplied, must be a Document, String, or IO. Documents have their context and Element attributes cloned. Strings are expected to be valid XML documents. IOs are expected to be sources of valid XML documents.

@param context if supplied, contains the context of the document; this should be a Hash.

NOTE that I'm not sure what the context is for; I cloned it out of the Electric XML API (in which it also seems to do nothing), and it is now legacy. It may do something, someday... it may disappear.

_コンストラクタ_

@もし、引数sourceを指定するのであればDocument、または String、あるいはIOでなければならない。Documentを与えた場合は、そ れらのコンテキスト、要素の属性の複製を持ちます。Stringを与える場 合は、妥当なXML文書である事を期待されます。IOを与える場合は、妥 当なXML文書のソースであることを期待されます。

@もし、引数contextを指定するのであればXML文書のコンテキ ストを含みます。;これはハッシュで与えられなければいけません。

私はコンテキストが何のためにあるのか自信が無い事を注意して下さ い。;私はそれを、Electric XML API (これも何もしていないように見 えます。)から複製しました。コンテキストは、現在はそれの遺産です。 それは、いつかなにかするかも知れません...それは無くなるかも知れ ません。

parse_stream( source, listener )

Stream parser. The source will be parsed as a Stream. If a block is supplied, yield will be called for tag starts, ends, and text. If a listener is supplied, the listener will also be notified, by calling the appropriate methods on events.

The arguments to the block will be:

 IF TAG START: "tag name", { attributes } (possibly empty)
 IF TEXT: "text"
 IF TAG END: "/tag name"

The listener must supply the following methods:

 tag_start( "name", { attributes } )
 tag_end( "name" )
 text( "text" )
 instruction( "name", "instruction" )
 comment( "comment" )
 doctype( "name", *contents )

ストリームパーサ。引数sourceはStreamとして構文解析されるでしょう。 もし、ブロックが与えられていれば、yieldはタグが始まる時、終る時、 そしてテキストが現れたときに呼び出されるでしょう。もし、引数 listenerが与えられていれば、listenerもまた、イベントでの適切なメ ソッド呼び出しとして通知されるでしょう。

ブロックのための引数はこうなるでしょう。

 もし、タグ始まったら: "タグ名", { 属性 } (たぶん空)
 もし、テキストが現れたら: "テキスト"
 もし、タグが終ったら: "/タグ名"

listenerは以下のようなメソッドを与えられるに違いありません。

 tag_start( "タグ名", { 属性 } )
 tag_end( "タグ名" )
 text( "テキスト" )
 instruction( "タグ名", "命令" )
 comment( "コメント" )
 doctype( "名前", *コンテキスト )
Public Instance methods
clone()

Should be obvious

明らかでしょう。

add( child )

We override this, because XMLDecls and DocTypes must go at the start of the document

私達はXMLDeclDocTypeがXML文書の始めに無ければいけないので、こ れをオーバーライドします。

add_element(arg=nil, arg2=nil)
root()

@return the root Element of the document, or nil if this document has no children.

@XML文書のルート要素を返します。もし、このXML文書が子を持たない のならnilを返します。

doc_type()

@return the DocType child of the document, if one exists, and nil otherwise.

@もし、存在しているなら、XML文書の子のDocTypeを返します。そうで なければnilを返します。

xml_decl()

@return the XMLDecl of this document; if no XMLDecl has been set, the default declaration is returned.

@XML文書のXMLDectを返します。もし、XMLDeclが設定されていなけ れば、デフォルトのXML宣言を返します。

version()

@return the XMLDecl version of this document as a String. If no XMLDecl has been set, returns the default version.

@XML文書のXMLDeclのバージョンをStringとして返します。もし、XMLDeclが 設定されていなければ、デフォルトのXMLバージョンを返します。

encoding()

@return the XMLDecl encoding of this document as a String. If no XMLDecl has been set, returns the default encoding.

@XML文書のXMLDeclのエンコードをStringとして返します。もし、 XMLDeclが設定されていなければデフォルトのエンコードを返します。

stand_alone?()

@return the XMLDecl standalone value of this document as a String. If no XMLDecl has been set, returns the default setting.

@XML文書のXMLDeclのスタンドアローンの値をStringとして返します。 もし、XMLDeclが設定されていなければデフォルトの設定を返します。

write( output, indent=-1 )

Write the XML tree out, optionally with indent. This writes out the entire XML document, including XML declarations, doctype declarations, and processing instructions (if any are given).

A controversial point is whether Document should always write the XML declaration (<?xml version='1.0'?>) whether or not one is given by the user (or source document). REXML does not write one if one was not specified, because it adds unneccessary bandwidth to applications such as XML-RPC.

@param output an object which supports '<< string'; this is where the document will be written

@param indent (optional) if given, the starting indent for the lines in the document.

任意のインデントでXMLツリーを書き出します。これはXML宣言、 DOCTYPE宣言、(もし与えられていれば)処理命令(PI)を含む全てのXML文 書を書き出します。

議論のポイントDocumentがいつもXML宣言(<?xml version='1.0'?>)を書 くべきかどうか、あるいは、Documentが書かずに、ユーザが書くか(あ るいはソース文書に書いておくか)どうかと言うことです。REXMLは、も し指定されていなければ書きません。なぜならば、それは、XML-RPCの ようなアプリケーションに不必要な回線容量を加えるからです。

@引数outputは'<< string'をサポートしているオブジェクトです。;こ れによって、XML文書に書き込むことができるでしょう。

@引数indent(オプション)は、もし与えられていれば、XML文書の各行の はじめをindent分インデントを指定します。

parse( source )

This and parse_stream could have been combined, but separating them improves the speed of REXML

これと、parse_streamは結合することができます。しかし、これらを分け ることがREXMLのスピードを改善しています。