Class: Serialbench::Serializers::Xml::LibxmlSerializer
Defined Under Namespace
Classes: StreamingHandler
Instance Method Summary
collapse
#available?, #features, format, #generate_xml, #parse_dom, #parse_sax, #supports_generation?, #supports_namespaces?, #supports_validation?, #supports_xpath?
#get_version, #initialize, #require_library, #stream_parse
Instance Method Details
#generate(data) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/serialbench/serializers/xml/libxml_serializer.rb', line 18
def generate(data)
require 'libxml'
if data.respond_to?(:to_s) && data.class.name.include?('LibXML')
data.to_s(indent: true)
else
doc = LibXML::XML::Document.new
doc.root = build_xml_from_data(data)
doc.to_s(indent: true)
end
end
|
#library_require_name ⇒ Object
52
53
54
|
# File 'lib/serialbench/serializers/xml/libxml_serializer.rb', line 52
def library_require_name
'libxml'
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/serialbench/serializers/xml/libxml_serializer.rb', line 9
def name
'libxml'
end
|
#parse(xml_string) ⇒ Object
13
14
15
16
|
# File 'lib/serialbench/serializers/xml/libxml_serializer.rb', line 13
def parse(xml_string)
require 'libxml'
LibXML::XML::Parser.string(xml_string).parse
end
|
#parse_streaming(xml_string, &block) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/serialbench/serializers/xml/libxml_serializer.rb', line 31
def parse_streaming(xml_string, &block)
require 'libxml'
handler = StreamingHandler.new(&block)
parser = LibXML::XML::SaxParser.string(xml_string)
parser.callbacks = handler
parser.parse
handler.elements_processed
end
|
#supports_streaming? ⇒ Boolean
41
42
43
|
# File 'lib/serialbench/serializers/xml/libxml_serializer.rb', line 41
def supports_streaming?
true
end
|
#version ⇒ Object
45
46
47
48
49
50
|
# File 'lib/serialbench/serializers/xml/libxml_serializer.rb', line 45
def version
return 'unknown' unless available?
require 'libxml'
LibXML::XML::VERSION
end
|