-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathxml_node.rb
More file actions
32 lines (26 loc) · 780 Bytes
/
xml_node.rb
File metadata and controls
32 lines (26 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true
require 'nokogiri'
module OpenscapParser
# Represents a generic Xml node with parsed_xml
class XmlNode
attr_reader :namespaces
def initialize(parsed_xml: nil)
@parsed_xml = parsed_xml
end
def parsed_xml(report_contents = '')
return @parsed_xml if @parsed_xml
@parsed_xml = ::Nokogiri::XML.parse(
report_contents, nil, nil, Nokogiri::XML::ParseOptions.new.norecover)
@namespaces = @parsed_xml.namespaces.clone
@parsed_xml.remove_namespaces!
end
def xpath_node(xpath)
parsed_xml && parsed_xml.at_xpath(xpath)
end
alias :at_xpath :xpath_node
def xpath_nodes(xpath)
parsed_xml && parsed_xml.xpath(xpath) || []
end
alias :xpath :xpath_nodes
end
end