Class: XmlWriteStream::Base
- Inherits:
-
Object
- Object
- XmlWriteStream::Base
show all
- Defined in:
- lib/xml-write-stream/base.rb
Constant Summary
collapse
- DEFAULT_INDENT =
4
- TAG_NAME_REGEX =
these are probably fairly incorrect, but good enough for now
/\A[a-zA-Z:_][\w.\-_:]*/
- ATTRIBUTE_KEY_REGEX =
/\A[a-zA-Z_][\w\-_]*/
- TEXT_ESCAPE_CHARS =
/["'<>&]/
- ATTRIBUTE_ESCAPE_CHARS =
/["'<>&\n\r\t]/
- TEXT_ESCAPE_HASH =
{
'"' => '"',
"'" => ''',
'<' => '<',
'>' => '>',
'&' => '&'
}
- ATTRIBUTE_ESCAPE_HASH =
TEXT_ESCAPE_HASH.merge({
"\n" => '
',
"\r" => '
',
"\t" => '	'
})
{
version: '1.0',
encoding: 'utf-8'
}
Instance Method Summary
collapse
Instance Method Details
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/xml-write-stream/base.rb', line 41
def (attributes = {})
stream.write('<?xml ')
write_attributes(
.merge(attributes)
)
stream.write('?>')
write_newline
end
|
#write_text(text, options = {}) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/xml-write-stream/base.rb', line 33
def write_text(text, options = {})
escape = options.fetch(:escape, true)
stream.write(
escape ? escape_text(text) : text
)
end
|