Class: XML::DOM::Document

Inherits:
Node
  • Object
show all
Defined in:
lib/xml/dom/core.rb,
lib/xml/dom2/document.rb

Overview

Class XML::DOM::Document

superclass

Node

Constant Summary collapse

XMLNSNS =
'http://www.w3.org/2000/xmlns/'

Constants inherited from Node

Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAGMENT_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::ENTITY_NODE, Node::ENTITY_REFERENCE_NODE, Node::NODE_NODE, Node::NOTATION_NODE, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE

Instance Method Summary collapse

Methods inherited from Node

#+, #<=>, #==, #[], #[]=, #__collectAncestorNS, #__collectDescendatNS, #__sibling, #_ancestor, #_child, #_descendant, #_following, #_fsibling, #_getChildIndex, #_getMyLocation, #_getMyLocationInXPath, #_getNodeByAbsoluteLocationTerm, #_insertNodes, #_matchAttribute?, #_matchNode?, #_matchNodeAttributes?, #_matchNodeType?, #_nodesByLocationTerms, #_nodesByRelativeLocationTerm, #_preceding, #_psibling, #_removeFromTree, #_removeNode, #_searchID, #accept, #accept_name, #appendChild, #attributes, #childNodes, #childNodes=, #children_accept, #children_accept_name, #cloneNode, #dump, #each, #firstChild, #getDigest, #getNodesByXPath, #getNodesByXPointer, #hasAttributes, #hasChildNodes, #insertBefore, #inspect, #isSupported, #lastChild, #localname, #makeXPath, #makeXPointer, #namespaceURI, #nextSibling, #nodeValue, #nodeValue=, #ownerDocument, #ownerDocument=, #parentNode, #parentNode=, #prefix, #prefix=, #previousSibling, #removeChild, #replaceChild, #to_s, #trim

Constructor Details

#initialize(*children) ⇒ Document

new([child1, child2, …]) or new(child1, child2, …)

child?: String or Node


1518
1519
1520
# File 'lib/xml/dom/core.rb', line 1518

def initialize(*children)
  super(*children)
end

Instance Method Details

#_checkNode(node) ⇒ Object



1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
# File 'lib/xml/dom/core.rb', line 1728

def _checkNode(node)
  unless node.nodeType == ELEMENT_NODE ||
      node.nodeType == PROCESSING_INSTRUCTION_NODE ||
      node.nodeType == COMMENT_NODE ||
      node.nodeType == DOCUMENT_TYPE_NODE
    raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
  end

  if node.nodeType == ELEMENT_NODE
    @children.each do |n|
      if n.nodeType == ELEMENT_NODE
        raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
      end
    end
  end

  if node.nodeType == DOCUMENT_TYPE_NODE
    @children.each do |n|
      if n.nodeType == DOCUMENT_TYPE_NODE
        raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
      end
    end
  end
end

#_getIDAttrsObject

get the ID list

experimental implement


1712
1713
1714
1715
# File 'lib/xml/dom/core.rb', line 1712

def _getIDAttrs
  return {'*'=>'id'} if @idattrs.nil?
  @idattrs
end

#_getNamespaces(parentNamespaces = {}, all = false) ⇒ Object



311
312
313
# File 'lib/xml/dom2/document.rb', line 311

def _getNamespaces(parentNamespaces = {}, all = false)
  { nil => nil }
end

#_setIDAttr(attrname, elemname = '*') ⇒ Object

set the ID list by the attribute name with the element name (or wildcard)

experimental implement


1705
1706
1707
1708
# File 'lib/xml/dom/core.rb', line 1705

def _setIDAttr(attrname, elemname = '*')
  @idattrs = {} if @idattrs.nil?
  @idattrs[elemname] = attrname
end

#createAttribute(name) ⇒ Object

DOM


1670
1671
1672
1673
1674
# File 'lib/xml/dom/core.rb', line 1670

def createAttribute(name)
  ret = Attr.new(name)
  ret.ownerDocument = self
  ret
end

#createAttributeNS(nsuri, qname) ⇒ Object

DOM2


258
259
260
261
262
263
# File 'lib/xml/dom2/document.rb', line 258

def createAttributeNS(nsuri, qname)
  nsuri = XMLNSNS if qname == 'xmlns' or qname =~ /^xmlns:/u
  ret = Attr.new([nsuri, qname])
  ret.ownerDocument = self
  ret
end

#createCDATASection(data) ⇒ Object

DOM


1631
1632
1633
1634
1635
# File 'lib/xml/dom/core.rb', line 1631

def createCDATASection(data)
  ret = CDATASection.new(data)
  ret.ownerDocument = self
  ret
end

#createComment(data) ⇒ Object

DOM


1644
1645
1646
1647
1648
# File 'lib/xml/dom/core.rb', line 1644

def createComment(data)
  ret = Comment.new(data)
  ret.ownerDocument = self
  ret
end

#createDocumentFragmentObject

DOM


1696
1697
1698
1699
1700
# File 'lib/xml/dom/core.rb', line 1696

def createDocumentFragment
  ret = DocumentFragment.new
  ret.ownerDocument = self
  ret
end

#createElement(tagName) ⇒ Object

DOM


1605
1606
1607
1608
1609
# File 'lib/xml/dom/core.rb', line 1605

def createElement(tagName)
  ret = Element.new(tagName)
  ret.ownerDocument = self
  ret
end

#createElementNS(nsuri, qname) ⇒ Object

DOM2


250
251
252
253
254
# File 'lib/xml/dom2/document.rb', line 250

def createElementNS(nsuri, qname)
  ret = Element.new([nsuri, qname])
  ret.ownerDocument = self
  ret
end

#createEntityReference(name) ⇒ Object

DOM


1683
1684
1685
1686
1687
# File 'lib/xml/dom/core.rb', line 1683

def createEntityReference(name)
  ret = EntityReference.new(name)
  ret.ownerDocument = self
  ret
end

#createProcessingInstruction(target, data) ⇒ Object

DOM


1657
1658
1659
1660
1661
# File 'lib/xml/dom/core.rb', line 1657

def createProcessingInstruction(target, data)
  ret = ProcessingInstruction.new(target, data)
  ret.ownerDocument = self
  ret
end

#createTextNode(data) ⇒ Object

DOM


1618
1619
1620
1621
1622
# File 'lib/xml/dom/core.rb', line 1618

def createTextNode(data)
  ret = Text.new(data)
  ret.ownerDocument = self
  ret
end

#doctypeObject

DOM


1569
1570
1571
1572
1573
1574
1575
1576
# File 'lib/xml/dom/core.rb', line 1569

def doctype
  @children.each do |child|
    if child.nodeType == DOCUMENT_TYPE_NODE
      return child
    end
  end if @children
  nil
end

#documentElementObject

DOM


1553
1554
1555
1556
1557
1558
1559
1560
# File 'lib/xml/dom/core.rb', line 1553

def documentElement
  @children.each do |child|
    if child.nodeType == ELEMENT_NODE
      return child
    end
  end if @children
  nil
end

#getElementById(elementId) ⇒ Object

DOM2


281
282
283
284
# File 'lib/xml/dom2/document.rb', line 281

def getElementById(elementId)
  ## [NOT IMPLEMENTED]
  raise "not implemented"
end

#getElementsByTagName(tagname) ⇒ Object

DOM

(but this is not “live”)



1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
# File 'lib/xml/dom/core.rb', line 1585

def getElementsByTagName(tagname)
  ret = NodeList.new
  @children.each do |node|
    if node.nodeType == ELEMENT_NODE
      if tagname == '*' || node.nodeName == tagname
        ret << node
      end
      ret << node.getElementsByTagName(tagname)
    end
  end if @children
  ret
end

#getElementsByTagNameNS(nsuri, localname) ⇒ Object

DOM2


266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/xml/dom2/document.rb', line 266

def getElementsByTagNameNS(nsuri, localname)
  ret = NodeList.new
  @children.each do |node|
    if node.nodeType == ELEMENT_NODE
      if (localname == '*' || node.localname == localname) and
          (nsuri == '*' || node.namespaceURI == nsuri)
        ret << node
      end
      ret << node.getElementsByTagNameNS(nsuri, localname)
    end
  end if @children
  ret
end

#implementationObject

DOM


1718
1719
1720
1721
1722
# File 'lib/xml/dom/core.rb', line 1718

def implementation
  return @implemantation if @implemantation
  ## singleton
  @implemantation = DOMImplementation.instance
end

#implementation=(impl) ⇒ Object



1724
1725
1726
# File 'lib/xml/dom/core.rb', line 1724

def implementation=(impl)
  @implemantation = impl
end

#importNode(impnode, deep) ⇒ Object

DOM2


238
239
240
241
# File 'lib/xml/dom2/document.rb', line 238

def importNode(impnode, deep)
  ## [NOT IMPLEMENTED]
  raise "not implemented"
end

#nodeNameObject

DOM


1542
1543
1544
# File 'lib/xml/dom/core.rb', line 1542

def nodeName
  "#document"
end

#nodeTypeObject

DOM


1531
1532
1533
# File 'lib/xml/dom/core.rb', line 1531

def nodeType
  DOCUMENT_NODE
end