Class: Xml::Kit::Document
- Inherits:
-
Object
- Object
- Xml::Kit::Document
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/xml/kit/document.rb
Overview
Constant Summary collapse
- NAMESPACES =
{ "ds": ::Xml::Kit::Namespaces::XMLDSIG }.freeze
Instance Method Summary collapse
-
#find_all(xpath) ⇒ Object
Returns all XML nodes found by searching the document with the provided XPath.
-
#find_by(xpath) ⇒ Object
Returns the first XML node found by searching the document with the provided XPath.
-
#initialize(raw_xml, namespaces: NAMESPACES) ⇒ Document
constructor
A new instance of Document.
-
#to_xml(pretty: true) ⇒ Object
Return the XML document as a [String].
Constructor Details
#initialize(raw_xml, namespaces: NAMESPACES) ⇒ Document
Returns a new instance of Document.
13 14 15 16 17 |
# File 'lib/xml/kit/document.rb', line 13 def initialize(raw_xml, namespaces: NAMESPACES) @raw_xml = raw_xml @namespaces = namespaces @document = ::Nokogiri::XML(raw_xml) end |
Instance Method Details
#find_all(xpath) ⇒ Object
Returns all XML nodes found by searching the document with the provided XPath.
29 30 31 |
# File 'lib/xml/kit/document.rb', line 29 def find_all(xpath) document.search(xpath, namespaces) end |
#find_by(xpath) ⇒ Object
Returns the first XML node found by searching the document with the provided XPath.
22 23 24 |
# File 'lib/xml/kit/document.rb', line 22 def find_by(xpath) document.at_xpath(xpath, namespaces) end |
#to_xml(pretty: true) ⇒ Object
Return the XML document as a [String].
36 37 38 |
# File 'lib/xml/kit/document.rb', line 36 def to_xml(pretty: true) pretty ? document.to_xml(indent: 2) : raw_xml end |