Class: Moxml::Adapter::CustomizedLibxml::Element
- Defined in:
- lib/moxml/adapter/customized_libxml/element.rb
Overview
Wrapper for LibXML element nodes
This wrapper provides automatic document import when adding children, solving LibXML’s strict document ownership requirement.
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#add_child(child) ⇒ Object
Add a child to this element, handling document import automatically.
Methods inherited from Node
#==, #document, #document_present?, #hash, #initialize
Constructor Details
This class inherits a constructor from Moxml::Adapter::CustomizedLibxml::Node
Instance Method Details
#add_child(child) ⇒ Object
Add a child to this element, handling document import automatically
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/moxml/adapter/customized_libxml/element.rb', line 14 def add_child(child) child_native = child.respond_to?(:native) ? child.native : child # Check if child needs to be imported if needs_import?(child_native) imported = @native.doc.import(child_native) @native << imported else @native << child_native end end |