Class: Serialbench::Serializers::Xml::NokogiriSerializer
Defined Under Namespace
Classes: StreamingHandler
Instance Method Summary
collapse
#available?, #features, format, #generate_xml, #parse_dom, #parse_sax, #xslt_apply
#get_version, #initialize, #require_library, #stream_parse, #supports?
Instance Method Details
#capabilities ⇒ Object
41
42
43
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 41
def capabilities
super | Set.new(i[xpath xslt validation sax stax])
end
|
#generate(data) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 18
def generate(data)
require 'nokogiri'
if data.respond_to?(:to_xml)
data.to_xml(indent: 2)
else
builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
build_xml_from_data(xml, data)
end
builder.to_xml
end
end
|
#library_require_name ⇒ Object
66
67
68
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 66
def library_require_name
'nokogiri'
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 9
def name
'nokogiri'
end
|
#parse(xml_string) ⇒ Object
13
14
15
16
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 13
def parse(xml_string)
require 'nokogiri'
Nokogiri::XML(xml_string)
end
|
#parse_streaming(xml_string, &block) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 32
def parse_streaming(xml_string, &block)
require 'nokogiri'
handler = StreamingHandler.new(&block)
parser = Nokogiri::XML::SAX::Parser.new(handler)
parser.parse(xml_string)
handler.elements_processed
end
|
#validate(document, schema) ⇒ Object
50
51
52
53
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 50
def validate(document, schema)
require 'nokogiri'
Nokogiri::XML::RelaxNG(schema).valid?(document)
end
|
#version ⇒ Object
59
60
61
62
63
64
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 59
def version
return 'unknown' unless available?
require 'nokogiri'
Nokogiri::VERSION
end
|
#xpath_query(document, expression) ⇒ Object
55
56
57
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 55
def xpath_query(document, expression)
document.xpath(expression).size
end
|
45
46
47
48
|
# File 'lib/serialbench/serializers/xml/nokogiri_serializer.rb', line 45
def xslt_transform(document, stylesheet)
require 'nokogiri'
Nokogiri::XSLT(stylesheet).transform(document).to_s
end
|