Class: XmlUtils::Document
- Inherits:
-
Node
- Object
- Node
- XmlUtils::Document
show all
- Defined in:
- lib/xmlutils/node.rb
Instance Attribute Summary collapse
Attributes inherited from Node
#parent
Instance Method Summary
collapse
Methods inherited from Node
#deep_clone, #document, #each, #next_sibling, #previous_sibling, #remove
Constructor Details
#initialize(standalone = nil) ⇒ Document
Returns a new instance of Document.
525
526
527
528
529
|
# File 'lib/xmlutils/node.rb', line 525
def initialize(standalone = nil)
super()
@children = []
@standalone = standalone
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
523
524
525
|
# File 'lib/xmlutils/node.rb', line 523
def children
@children
end
|
Instance Method Details
#add(element) ⇒ Object
Also known as:
<<
535
536
537
538
539
|
# File 'lib/xmlutils/node.rb', line 535
def add(element)
element.parent = self
@children << element
element
end
|
#context ⇒ Object
581
582
583
|
# File 'lib/xmlutils/node.rb', line 581
def context
{}
end
|
#delete(element) ⇒ Object
542
543
544
545
|
# File 'lib/xmlutils/node.rb', line 542
def delete(element)
@children.delete(element)
element.parent = nil if element.respond_to?(:parent=)
end
|
#doctype ⇒ Object
568
569
570
|
# File 'lib/xmlutils/node.rb', line 568
def doctype
@children.find { |c| c.is_a?(DocType) }
end
|
#each_element(&block) ⇒ Object
572
573
574
575
|
# File 'lib/xmlutils/node.rb', line 572
def each_element(&block)
return to_enum(:each_element) unless block_given?
@children.select { |c| c.is_a?(Element) }.each(&block)
end
|
#elements ⇒ Object
577
578
579
|
# File 'lib/xmlutils/node.rb', line 577
def elements
@children.select { |c| c.is_a?(Element) }
end
|
#node_type ⇒ Object
531
532
533
|
# File 'lib/xmlutils/node.rb', line 531
def node_type
:document
end
|
#root ⇒ Object
547
548
549
|
# File 'lib/xmlutils/node.rb', line 547
def root
@children.find { |c| c.is_a?(Element) }
end
|
#to_s ⇒ Object
558
559
560
561
562
|
# File 'lib/xmlutils/node.rb', line 558
def to_s
output = ""
write(output)
output
end
|
#write(output = $stdout, indent = 0) ⇒ Object
551
552
553
554
555
556
|
# File 'lib/xmlutils/node.rb', line 551
def write(output = $stdout, indent = 0)
@children.each_with_index do |child, idx|
child.write(output, indent)
output << "\n" unless idx == @children.length - 1
end
end
|
#xml_decl ⇒ Object
564
565
566
|
# File 'lib/xmlutils/node.rb', line 564
def xml_decl
@children.find { |c| c.is_a?(XMLDecl) || (c.is_a?(ProcessingInstruction) && c.respond_to?(:target) && c.target == 'xml') }
end
|