Class: XmlPatch::TargetDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/xml_patch/target_document.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ TargetDocument

Returns a new instance of TargetDocument.



7
8
9
10
11
# File 'lib/xml_patch/target_document.rb', line 7

def initialize(xml)
  @xml = Oga.parse_xml(xml)
rescue LL::ParserError => e
  raise XmlPatch::Errors::InvalidXml, e.message
end

Instance Method Details

#remove_at!(xpath) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/xml_patch/target_document.rb', line 17

def remove_at!(xpath)
  nodes = []

  begin
    nodes = xml.xpath(xpath)
  rescue LL::ParserError => e
    raise XmlPatch::Errors::InvalidXpath, e.message
  end

  nodes.each { |n| remove_node(n) }

  self
end

#to_xmlObject



13
14
15
# File 'lib/xml_patch/target_document.rb', line 13

def to_xml
  xml.to_xml
end