class RExpat
This is a main parser class.
The on_ methods are event handlers.
This work is licensed under the Ruby license or the Expat license.
Constants
- VERSION
Public Class Methods
() → String
Source
# File lib/rexpat.rb, line 15
Get expat version.
expat のバージョンを得ます。
() → Hash[String, Integer]
Source
# File lib/rexpat.rb, line 22
Get a hash list of expat API’s features.
(encoding: String?, nssep: String?) → RExpat
Source
# File lib/rexpat.rb, line 28
encoding can be specified to ISO-8859-1, UTF-8, US-ASCII and UTF-16, which Expat can recognize.
nssep enables namespace extension. The namespace-prefixed element and attribute names are concatenated with the namespace’s URI and a separator (the first byte of nssep).
For example, with nssep = '!',
<hoge:test xmlns:hoge="http://www.yoshidam.net/ns/hoge">
is parsed into
http://www.yoshidam.net/ns/hoge!test
It can raise RExpat::Error.
See also reset for reusing the parser. Note that the xmlparser gem prohibits the reuse, I don’t know why.
作成に失敗すると RExpat::Error 例外が発生します。 encoding として文字エンコーディングを外部から指定することも出来ます。Expat が対応しているエンコーディング名(ISO-8859-1, UTF-8, US-ASCII, UTF-16) が使えます。
nssep を指定すると名前空間拡張が有効になります。エレメントや属性の名前にプレフィックスを指定すると,エレメント名や属性名が URI とローカルパートを連結した名前になります。 nssep で指定された文字列の最初の文字がセパレータになります。
例えば
<hoge:test xmlns:hoge="http://www.yoshidam.net/ns/hoge">
を nssep = '!' でパースすると,エレメント名は
http://www.yoshidam.net/ns/hoge!test
になります。
Public Instance Methods
(String) → void
Source
# File lib/rexpat.rb, line 125
The value is assigned as the URL base for external entities. See also the on_external_entity_ref event handler.
This can raise RExpat::Error when out of memory.
() → Integer
Source
# File lib/rexpat.rb, line 175
Get the number of bytes in the current event. This should be called in event handlers.
When the event is in an internal entity, this method returns 0.
イベントハンドラ内で呼び出します。現在のイベント対象の長さを返します。内部実体では 0 を返します。
() → Integer
Source
# File lib/rexpat.rb, line 161
() → Integer
Source
# File lib/rexpat.rb, line 148
Get current parsing location.
When a parse method raises RExpat::Error, these method return the position of the error detected.
See also line and byte_index.
イベントハンドラ内で呼び出します。現在のパース位置を返します。また,parse メソッドが RExpat::Error 例外で発生した時に呼び出すとエラー位置を返します。
() → void
Source
# File lib/rexpat.rb, line 111
Raise a on_default event within any event handlers. You can get the corresponding markup.
If within a event handler, it raise a on_default event immediately.
イベントハンドラ内で呼び出します。 on_default イベントを発生させ,パース前の生のデータを得ることができます。イベントハンドラ内ですぐさま on_default イベントが発生します。 on_default ハンドラーは呼び出されないことに注意して下さい。
(context: String, encoding: String?) → RExpat
Source
# File lib/rexpat.rb, line 72
This creates an XML parser object that can parse an external entity. It can raise RExpat::Error.
This can be called at any point after the first on_external_entity_ref event call.
The context parameter should be the parsing context given by the on_external_entity_ref event.
The encoding parameter is an optional character encoding.
The returned parser can be reused by calling reset.
() → String
Source
# File lib/rexpat.rb, line 234
Gets the ID attribute name.
This method should be used in on_start_element event handler.
Note that the ID attribute here is the one declared in the doctype declaration, rather than the one with an xml:id attribute nor a plain id attribute. For example, in this XML document, foo is the ID attribute:
<!DOCTYPE test [
<!ELEMENT root EMPTY>
<!ATTLIST root
foo ID #REQUIRED
>
]>
<root foo="bar"/>
ID 属性の名前を得ます。on_start_element イベント内で呼び出してください。
() → [ String, Integer ]
Source
# File lib/rexpat.rb, line 226
Returns the parser’s input buffer and current parse posion.
入力バッファと現在パース位置を得ます。
() → Integer
Source
# File lib/rexpat.rb, line 134
Get current parsing location.
When a parse method raises RExpat::Error, these method return the position of the error detected.
See also column and byte_index.
イベントハンドラ内で呼び出します。現在のパース位置を返します。また,parse メソッドが RExpat::Error 例外で発生した時に呼び出すとエラー位置を返します。
(String, String, String?, String, bool) → void
Source
# File lib/rexpat.rb, line 509
属性宣言時に呼び出されます。 elname は要素名, attname は属性名, att_type は属性の型, dflt は省略値,isrequired は#REQUIRED かどうかをあらわします。
(String) → void
Source
# File lib/rexpat.rb, line 302
This method is called when texts or CDATA sections are detected. Internal entities are expanded as long as on_default handler is not defined.
テキスト,CDATA セクションを見付けると呼び出されます。on_default ハンドラが未定義のときは内部実体は展開されます。
(String) → void
Source
# File lib/rexpat.rb, line 378
This methods is called when comments are detected.
コメントを見付けると呼び出されます。
(String) → void
Source
# File lib/rexpat.rb, line 451
This method is called when there is no applicable event handler.
If this method is defined, expansion of internal entities are inhibited.
他のイベントが呼び出されなかった場合に呼び出されます。このメソッドを定義すると内部実体の展開が抑止されます。
(String) → void
Source
# File lib/rexpat.rb, line 464
This method is called when there is no applicable event handlers. This is almost same as on_default, except it expands internal entity references.
This method have higher priority than on_default method.
他のイベントが呼び出されなかった場合に呼び出されます。on_default_expand は on_default メソッドに優先します。
(String, model_type) → void
Source
# File lib/rexpat.rb, line 498
要素宣言時に呼び出されます。 name は要素名, model は内容モデルをあらわす[type, quant, name, [children_model, ...]]のような配列です。 type は :empty, :any, :mixed, :choice, :seq のいずれか, quant は :none, :opt, :rep, :plus のいずれかです。 name は nil か要素名, children_model は子モデルです。
() → void
Source
# File lib/rexpat.rb, line 395
This method is called when CDATA sections end.
CDATA セクションの終了時に呼び出されます。
() → void
Source
# File lib/rexpat.rb, line 443
This methods is called when the closing > is encountered, but after processing any external subset.
DOCTYPE 宣言の終了時に呼び出されます。
(String) → void
Source
# File lib/rexpat.rb, line 292
This method is called when element end tags are detected. name is the element name.
エレメント終了タグを見付けると呼び出されます。 name はエレメント名です。
(String?) → void
Source
# File lib/rexpat.rb, line 418
This methods is called after the element that has namespace declaration.
Prefix can be nil.
Note that the namespace support is enabled only when RExpat.new‘s nssep is set.
Namespace 宣言されたエレメントの終了後に呼び出されます。prefix は xmlns 属性が指定された場合は nil になります。
(String, bool, String, String?, String?, String?, String?) → void
Source
# File lib/rexpat.rb, line 530
実体宣言時に呼び出されます。
(String, String?, String?, String?) → void
Source
# File lib/rexpat.rb, line 336
This method is called when external entity references are detected. context, base, systemId, and publicId are the parsing context, the URL base, the system identifier, and the public identifier. The URL base, the system identifier, and the public identifier can be nil. The context can use the context parameter of the constructor of the external entity parser.
If you do not parse the external entities by this event, the external entities are never parsed.
It is called when external parameter entity refs (including external DTD subset) are detected. In this case, context will be nil. The parser for the external parameter entitiy must be created with parse in this event. See also param_entity_parsing=.
Example:
def externalEntityRef(context, base, systemId, publicId) extp = self.type.new(self, context) file = if base.nil?; systemId; else base + "/" + systemId; end extp.parse(open(file)) end
外部実体参照を見付けると呼び出されます。 context, base, systemId, publicId はそれぞれパースコンテクスト,URL ベース,システム識別子,公開識別子です。URL ベース,公開識別子 は nil になることがあります。パースコンテクストは外部実体パース用のパーサを生成するときの context 引数として利用可能です。
このイベントで外部実体をパースしなければ,外部実体はパースされることはありません。
外部パラメータ実体参照 (および外部 DTD サブセット) を見付けた場合にも呼び出されます。この場合は context は nil になります。外部パラメータ実体をパースする場合は必ずこのハンドラ内でパースしてください。 param_entity_parsing= も参照してください。
() → bool
Source
# File lib/rexpat.rb, line 477
This methods is called if the document is not standalone (it has an external subset or a reference to a parameter entity, but does not have standalone="yes").
If you may return false to raise an error, or return true to continue the parsing.
standalone="yes" でない時,外部 DTD サブセットやパラメータ実体を参照すると呼び出されます。
エラーを発生させたい場合は false,処理を続行させたい場合は true を返してください。
expat は外部 DTD サブセットやパラメータ実体を解決できないので,このイベントが発生した場合は他の XML プロセッサを呼び出すなり,処理を中断するなりすべきかもしれません。
(String, String?, String?, String?) → void
Source
# File lib/rexpat.rb, line 321
This methods is called when notation declarations are detected. notationName, base, systemId, and publicId are the notation name, the URL base, the system identifier and the public identifier. The URL base, the system identifier and the public identifier can be nil.
記法宣言を見付けると呼び出されます。 notationName, base, systemId, publicId はそれぞれ記法名,URL ベース,システム識別子,公開識別子です。URL ベース,システム識別子,公開識別子 は nil になることがあります。
(String, String) → void
Source
# File lib/rexpat.rb, line 313
This method is called when processing instructions are detected.
PI を見付けると呼び出されます。
(String, bool) → void
Source
# File lib/rexpat.rb, line 537
Source
# File lib/rexpat.rb, line 386
This methods is called when CDATA sections start. The contents of the CDATA sections are reported by on_character_data event.
CDATA セクションの開始時に呼び出されます。CDATA セクションの内容はon_character_data イベントで報告されます。
(String, String?, String?, bool) → void
Source
# File lib/rexpat.rb, line 433
This methods is called when the name of the DOCTYPE is encountered.
DOCTYPE 宣言の文書型名を見つけると呼び出されます。doctypeName は文書型名です。
(String, Hash[String, String]) → void
Source
# File lib/rexpat.rb, line 281
This method is called when element start tags are detected. name is the element name, attrs is a hash of attributes, the keys are the attribute’s name, the values are attribute’s values.
エレメント開始タグを見付けると呼び出されます。 name はエレメント名, attrs は属性名をキー,属性値を値とするハッシュです。
(String?, String?) → void
Source
# File lib/rexpat.rb, line 402
This methods is called before the element that has namespace declaration.
prefix and uri can be nil.
Note that the namespace support is enabled only when RExpat.new‘s nssep is set.
Namespace 宣言されたエレメントの開始前に呼び出されます。prefix は xmlns 属性が指定された場合は nil になり, uriは空 URI が指定された場合に nil になります。
(String, String, bool?) → void
Source
# File lib/rexpat.rb, line 517
standalone can be either nil, false, or true, which means “no standalone attribute”, “standalone attribute is set to no”, and “standalone attribute is set to yes”, respectably.
文書先頭の XML 宣言および解析可能実体のテキスト宣言時に呼び出されます。テキスト宣言では version が nil に,XML 宣言ではencoding が nil になることがあります。standalone は nil, false, true の値をとります。
(:never | :unless_standalone | :always) → void
Source
# File lib/rexpat.rb, line 192
Controls parsing of parameter entities, including the external DTD subset.
parsing parameter is either of :never, :unless_standalone, or :always.
References to external parameter entities will invoke the on_external_entity_ref event. The context will be nil.
This can raise RExpat::Error.
外部パラメータ実体(外部 DTD サブセットも含む) をパースするかどうかを指定します。 parsing には :never, :unless_standalone, :alwaysのいずれかを指定してください。
外部パラメータエンティティをパースする場合,on_external_entity_refイベントが呼び出されます。 context はnil になります。
(String?, final: bool) → void
Source
# File lib/rexpat.rb, line 89
Parse a string. The parse results can be processed by event handlers.
final parameter must true on last call of this method. Default is true. No parameter call of this method indicates the end of parsing.
A failure to parse raises a RExpat::Error exception.
str をパースします。パース結果としてイベントハンドラが呼び出されます。
final は XML の途中までパースする場合は false, 最後までの場合はtrue を指定して下さい。省略時は true です。引数無しで呼び出すことで,パースの終了を指示することもできます。
パースエラーを検出すると RExpat::Error 例外が発生します。
(encoding: String?) → void
Source
# File lib/rexpat.rb, line 257
Resets the parser object to be reused. The encoding parameter can specify the character encoding.
See also external_entity_parser.
パーサオブジェクトを再利用するためにリセットします。encoding として文字エンコーディングを外部から指定することもできます。
(bool) → void
Source
# File lib/rexpat.rb, line 215
Sets namespace triplet flag. It tells whether to use the URI, the local name, and the prefix if the namespace is enabled, or always use the URI and the local name if false.
名前空間が有効なときに,URI + ローカル名 + プレフィックスを使うかどうか指示します。 false の時はURI + ローカル名です。
() → Array[String]
Source
# File lib/rexpat.rb, line 186
This returns an array of specified attribute names. This method should be used in the on_start_element event handler.
(bool) → void
Source
# File lib/rexpat.rb, line 269
Specifies to parse an external DTD subset without the DOCTYPE declaration.
In on_external_entity_ref, th esystem ID and the public ID will be nil.
See also param_entity_parsing=.