Class: XmlPatch::TargetDocument
- Inherits:
-
Object
- Object
- XmlPatch::TargetDocument
- Defined in:
- lib/xml_patch/target_document.rb
Instance Method Summary collapse
-
#initialize(xml) ⇒ TargetDocument
constructor
A new instance of TargetDocument.
- #remove_at!(xpath) ⇒ Object
- #to_xml ⇒ Object
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. 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. end nodes.each { |n| remove_node(n) } self end |
#to_xml ⇒ Object
13 14 15 |
# File 'lib/xml_patch/target_document.rb', line 13 def to_xml xml.to_xml end |