[DRE-commits] [ruby-xmlparser] 01/03: unapply patches
Lucas Nussbaum
lucas at moszumanska.debian.org
Wed May 6 20:40:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
lucas pushed a commit to branch master
in repository ruby-xmlparser.
commit 2bcb218066e7872ee3bbac4009aa14d61aa1990c
Author: Lucas Nussbaum <lucas at debian.org>
Date: Wed May 6 22:24:38 2015 +0200
unapply patches
---
.pc/.quilt_patches | 1 -
.pc/.quilt_series | 1 -
.pc/.version | 1 -
.pc/applied-patches | 2 -
.pc/move-files-to-ext.patch/.timestamp | 0
.pc/move-files-to-ext.patch/ext/encoding.h | 0
.pc/move-files-to-ext.patch/ext/extconf.rb | 0
.pc/move-files-to-ext.patch/ext/xmlparser.c | 0
.../.timestamp | 0
.../lib/xml/dom/core.rb | 3276 --------------------
.../lib/xml/dom2/attr.rb | 213 --
ext/encoding.h | 91 -
ext/extconf.rb | 58 -
ext/xmlparser.c | 2292 --------------
lib/xml/dom/core.rb | 2 -
lib/xml/dom2/attr.rb | 4 +-
16 files changed, 1 insertion(+), 5940 deletions(-)
diff --git a/.pc/.quilt_patches b/.pc/.quilt_patches
deleted file mode 100644
index 6857a8d..0000000
--- a/.pc/.quilt_patches
+++ /dev/null
@@ -1 +0,0 @@
-debian/patches
diff --git a/.pc/.quilt_series b/.pc/.quilt_series
deleted file mode 100644
index c206706..0000000
--- a/.pc/.quilt_series
+++ /dev/null
@@ -1 +0,0 @@
-series
diff --git a/.pc/.version b/.pc/.version
deleted file mode 100644
index 0cfbf08..0000000
--- a/.pc/.version
+++ /dev/null
@@ -1 +0,0 @@
-2
diff --git a/.pc/applied-patches b/.pc/applied-patches
deleted file mode 100644
index 3703a0d..0000000
--- a/.pc/applied-patches
+++ /dev/null
@@ -1,2 +0,0 @@
-replaces_gt_symbol_by_enconded_version.patch
-move-files-to-ext.patch
diff --git a/.pc/move-files-to-ext.patch/.timestamp b/.pc/move-files-to-ext.patch/.timestamp
deleted file mode 100644
index e69de29..0000000
diff --git a/.pc/move-files-to-ext.patch/ext/encoding.h b/.pc/move-files-to-ext.patch/ext/encoding.h
deleted file mode 100644
index e69de29..0000000
diff --git a/.pc/move-files-to-ext.patch/ext/extconf.rb b/.pc/move-files-to-ext.patch/ext/extconf.rb
deleted file mode 100644
index e69de29..0000000
diff --git a/.pc/move-files-to-ext.patch/ext/xmlparser.c b/.pc/move-files-to-ext.patch/ext/xmlparser.c
deleted file mode 100644
index e69de29..0000000
diff --git a/.pc/replaces_gt_symbol_by_enconded_version.patch/.timestamp b/.pc/replaces_gt_symbol_by_enconded_version.patch/.timestamp
deleted file mode 100644
index e69de29..0000000
diff --git a/.pc/replaces_gt_symbol_by_enconded_version.patch/lib/xml/dom/core.rb b/.pc/replaces_gt_symbol_by_enconded_version.patch/lib/xml/dom/core.rb
deleted file mode 100644
index ab260e7..0000000
--- a/.pc/replaces_gt_symbol_by_enconded_version.patch/lib/xml/dom/core.rb
+++ /dev/null
@@ -1,3276 +0,0 @@
-## -*- Ruby -*-
-## XML::SimpleTree
-## 1998-2000 by yoshidam
-##
-## XPointer support is contributed by Masaki Fukushima
-## <fukusima at goto.info.waseda.ac.jp>
-##
-
-require 'singleton'
-
-=begin
-
-= XML::DOM (XML::SimpleTree)
-
-=end
-
-
-=begin
-
-== Module XML
-
-=end
-
-module XML
-
-=begin
-=== Class Methods
-
- --- XML.charRef(s)
-
-replace character '&','<','>',"'",'"' in string s to character reference.
-=end
-
- def XML.charRef(s)
- str = s.dup
- str.gsub!("&", "&")
- str.gsub!("<", "<")
- str.gsub!(">", ">")
- str.gsub!("'", "'")
- str.gsub!('"', """)
- str
- end
-
-=begin
-
-== Module XML::Spec
-
-Constants related to XML Specification.
-
-=end
- ## [Masaki Fukushima]
- module Spec
- ## Constants related to XML Specification
- ## (W3C Recommendation or Working Draft)
-
- # XML
- Letter_s = '[a-zA-Z]'
- Digit_s = '\d'
- NameChar_s = "(#{Letter_s}|#{Digit_s}|[\\.\\-_:])"
- Name_s = "(#{Letter_s}|[_:])#{NameChar_s}*"
- SkipLit_s = "(\"[^\"]*\"|'[^']*')"
- Name = /^#{Name_s}$/o
- SkipList = /^#{SkipLit_s}$/o
-
- # XPointer
- Instance_s = "(\\+|-)?[1-9]#{Digit_s}*"
- Instance = /^#{Instance_s}$/o
-
- end
-
-=begin
-
-== Module XML::DOM (XML::SimpleTree)
-
-DOM-like APIs module.
-
-=end
-
- module DOM
-
- ## Fundamental Interfaces
-
-=begin
-
-== Class XML::DOM::DOMException
-
-=== superclass
-Exception
-
-DOM exception.
-=end
-
- class DOMException<Exception
- INDEX_SIZE_ERR = 1
- WSTRING_SIZE_ERR = 2
- HIERARCHY_REQUEST_ERR = 3
- WRONG_DOCUMENT_ERR = 4
- INVALID_NAME_ERR = 5
- NO_DATA_ALLOWED_ERR = 6
- NO_MODIFICATION_ALLOWED_ERR = 7
- NOT_FOUND_ERR = 8
- NOT_SUPPORTED_ERR = 9
- INUSE_ATTRIBUTE_ERR = 10
- ERRMSG = [
- "no error",
- "index size",
- "wstring size",
- "hierarchy request",
- "wrong document",
- "invalid name",
- "no data allowed",
- "no modification allowed",
- "not found",
- "not supported",
- "inuse attribute"
- ]
-
-=begin
-=== Class Methods
-
- --- DOMException.new(code = 0)
-
-generate DOM exception.
-=end
-
- def initialize(code = 0)
- @code = code
- end
-
-=begin
-=== Methods
-
- --- DOMException#code()
-
-return code of exception.
-
-=end
- def code
- @code
- end
-
-=begin
-
- --- DOMException#to_s()
-
-return the string representation of the error.
-
-=end
- def to_s
- ERRMSG[@code]
- end
- end
-
-=begin
-== Class XML::DOM::DOMImplementation
-
-=end
- class DOMImplementation
- include Singleton
-
-=begin
- --- DOMImplementation#hasFeature(feature, version)
-
-test if DOM implementation has correct feature and version.
-
-=end
- def hasFeature(feature, version)
- if feature =~ /^XML$/i && (version.nil? || version == "1.0")
- return true
- end
- false
- end
- end
-
-=begin
-== Class XML::DOM::Node
-
-=end
- class Node
- ## [DOM]
- NODE_NODE = 0
- ELEMENT_NODE = 1
- ATTRIBUTE_NODE = 2
- TEXT_NODE = 3
- CDATA_SECTION_NODE = 4
- ENTITY_REFERENCE_NODE = 5
- ENTITY_NODE = 6
- PROCESSING_INSTRUCTION_NODE = 7
- COMMENT_NODE = 8
- DOCUMENT_NODE = 9
- DOCUMENT_TYPE_NODE = 10
- DOCUMENT_FRAGMENT_NODE = 11
- NOTATION_NODE = 12
-
- ## non-DOM
-# NODE = 0
-# ELEMENT = 1
-# ATTRIBUTE = 2
-# TEXT = 3
-# CDATA_SECTION = 4
-# ENTITY_REFERENCE = 5
-# ENTITY = 6
-# PI = 7
-# PROCESSING_INSTRUCTION = 7
-# COMMENT = 8
-# DOCUMENT = 9
-# DOCUMENT_TYPE = 10
-# DOCUMENT_FRAGMENT = 11
-# NOTATION = 12
-
-=begin
-=== Class Methods
-
- --- Node.new(*children)
-
-make a Node.
-children is a Array of child, or sequence of child.
-child is a String or Node.
-
-=end
- ## new([child1, child2, ...]) or
- ## new(child1, child2, ...)
- ## child?: String or Node
- def initialize(*children)
- @parent = nil
- @children = nil
- self.childNodes = children if children.length > 0
- end
-
-=begin
-=== Methods
-
- --- Node#parentNode
-
-[DOM]
-return parent node.
-
-=end
- ## [DOM]
- def parentNode
- @parent
- end
-
-=begin
- --- Node#parentNode=(p)
-
-set node p as parent.
-=end
-
- def parentNode=(p)
- @parent = p
- end
-
-=begin
- --- Node#nodeType
-
-[DOM]
-return nodetype.
-
-=end
- ## [DOM]
- def nodeType
- NODE_NODE
- end
-
-=begin
- --- Node#nodeName
-
-[DOM]
-return nodename.
-
-=end
- ## [DOM]
- def nodeName
- "#node"
- end
-
-# def nodeName=(p)
-# @name = p
-# end
-
-=begin
- --- Node#nodeValue
-
-[DOM]
-return nodevalue.
-
-=end
- ## [DOM]
- def nodeValue; nil; end
-
-=begin
- --- Node#nodeValue=(p)
-
-[DOM]
-set nodevalue as p.
-=end
- ## [DOM]
- def nodeValue=(p)
- ## no effect
- end
-
-=begin
- --- Node#childNodes()
-
-[DOM]
-if method has block, apply block for children nodes.
-without block, return children nodelist.
-=end
- ## [DOM]
- def childNodes
- if iterator?
- @children.each do |child|
- yield(child)
- end if @children
- else
- return @children if !@children.nil?
- @children = NodeList.new
- end
- end
-
-
-=begin
- --- Node#childNodes=(p)
-
-set child node as p.
-=end
- def childNodes=(p)
- if @children.nil?
- @children = NodeList.new
- else
- @children.to_a.clear
- end
- if p.nil? || (p.is_a?(Array) && p.length == 0)
- return
- end
- p.flatten!
- p.each do |child|
- if child.is_a?(String)
- c = Text.new(child)
- @children.push(c)
- c.parentNode = self
- elsif child.is_a?(Node)
- @children.push(child)
- child.parentNode = self
- else
- raise "parameter error"
- end
- end if p
- end
-
-=begin
- --- Node#attributes
-
-[DOM]
-return attributes of node(but always return nil?).
-=end
- ## [DOM]
- def attributes
- nil
- end
-
- ## proper parameter type?
-# def attributes=(p)
-# end
-
-=begin
- --- Node#[]=(index, nodes)
-
-set children node as nodes with []-style.
-=end
- def []=(index, nodes)
- @children[index..index] = nodes
- @children.each do |child|
- child.parentNode = self
- end if @children
- end
-
-=begin
- --- Node#[](index)
-
-get children node with []-style.
-=end
- def [](index)
- @children[index]
- end
-
-=begin
- --- Node#+(node)
-
-concat node to Node.
-=end
- def +(node)
- [self, node]
- end
-
-=begin
- --- Node#to_s
-
-returns the string representation of the Node.
-=end
- def to_s
- @children.to_s
- end
-
-=begin
- --- Node#dump(depth = 0)
-
-dump the Node.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print nodeName + "\n"
- @children.each do |child|
- child.dump(depth + 1)
- end if @children
- end
-
-=begin
- --- Node#inspect()
-
-returns the human-readable string representation.
-=end
- def inspect
- "#<#{self.class}: #{self.nodeName}>"
- end
-
-=begin
- --- Node#firstChild()
-
-[DOM]
-return the first child node.
-=end
- ## [DOM]
- def firstChild
- return nil if !@children || @children.length == 0
- return @children[0]
- end
-
-=begin
- --- Node#lastChild()
-
-[DOM]
-return the last child node.
-=end
- ## [DOM]
- def lastChild
- return nil if !@children || @children.length == 0
- return @children[-1]
- end
-
-=begin
- --- Node#previousSibling()
-
-[DOM]
-return the previous sibling node.
-=end
- ## [DOM]
- def previousSibling
- return nil if !@parent
- prev = nil
- @parent.childNodes do |child|
- return prev if child == self
- prev = child
- end
- nil
- end
-
-=begin
- --- Node#nextSibling()
-
-[DOM]
-return the next sibling node.
-=end
- ## [DOM]
- def nextSibling
- return nil if !@parent
- nexts = nil
- @parent.childNodes.reverse.each do |child|
- return nexts if child == self
- nexts = child
- end
- nil
- end
-
- def _getChildIndex(node)
- index = 0
- @children.each do |child|
- if child == node
- return index
- end
- index += 1
- end
- nil
- end
-
- def _removeFromTree
- parent = parentNode
- if parent
- parent.removeChild(self)
- end
- end
-
- def _checkNode(node)
- raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
- end
-
- def _insertNodes(index, node)
- if node.nodeType == DOCUMENT_FRAGMENT_NODE
-
- node.childNodes.to_a.each_with_index do |n, i|
- if index == -1
- _insertNodes(-1, n)
- else
- _insertNodes(index + i, n)
- end
- end
- elsif node.is_a?(Node)
- ## to be checked
- _checkNode(node)
- node._removeFromTree
- if index == -1
- @children.push(node)
- else
- @children[index, 0] = node
- end
- node.parentNode = self
- else
- raise ArgumentError, "invalid value for Node"
- end
- end
-
- def _removeNode(index, node)
- @children[index, 1] = nil
- node.parentNode = nil
- end
-
-# =begin
-# --- Node#insertAfter(newChild, refChild)
-#
-# insert newChild into the node after refChild.
-# =end
-# def insertAfter(newChild, refChild)
-# if @children.nil? || @children.length == 0
-# raise DOMException.new(DOMException::NOT_FOUND_ERR)
-# end
-# index = _getChildIndex(refChild)
-# raise DOMException.new(DOMException::NOT_FOUND_ERR) if index.nil?
-# _insertNodes(index, newChild)
-# end
-
-=begin
- --- Node#insertBefore(newChild, refChild)
-
-[DOM]
-insert newChild into the node before refChild.
-=end
- ## [DOM]
- def insertBefore(newChild, refChild)
- if @children.nil? || @children.length == 0
- raise DOMException.new(DOMException::NOT_FOUND_ERR)
- end
- index = _getChildIndex(refChild)
- raise DOMException.new(DOMException::NOT_FOUND_ERR) if !index
- _insertNodes(index, newChild)
- end
-
-=begin
- --- Node#replaceChild(newChild, oldChild)
-
-[DOM]
-replace the child node oldChild with newChild.
-=end
- ## [DOM]
- def replaceChild(newChild, oldChild)
- if @children.nil? || @children.length == 0
- raise DOMException.new(DOMException::NOT_FOUND_ERR)
- end
- index = _getChildIndex(oldChild)
- raise DOMException.new(DOMException::NOT_FOUND_ERR) if !index
- _removeNode(index, oldChild)
- _insertNodes(index, newChild)
- end
-
-=begin
- --- Node#removeChild(oldChild)
-
-[DOM]
-remove the children node oldChild.
-=end
- ## [DOM]
- def removeChild(oldChild)
- if @children.nil? || @children.length == 0
- raise DOMException.new(DOMException::NOT_FOUND_ERR)
- end
- index = _getChildIndex(oldChild)
- raise DOMException.new(DOMException::NOT_FOUND_ERR) if !index
- _removeNode(index, oldChild)
- oldChild
- end
-
-=begin
- --- Node#appendChild(newChild)
-
-[DOM]
-adds the node newChild to the end of the list of children of this node.
-=end
- ## [DOM]
- def appendChild(newChild)
- @children = NodeList.new if !@children
- _insertNodes(-1, newChild)
- end
-
-=begin
- --- Node#hasChildNodes()
-
-[DOM]
-returns true if node has children, or return false if node has no children.
-=end
- ## [DOM]
- def hasChildNodes
- !@children.nil? && @children.length > 0
- end
-
- ## get the Node object by IDs
- ## [experimental implement]
- def _searchID(value, ids = nil)
- if ids.nil?
- doc = nil
- if nodeType == DOCUMENT_NODE
- doc = self
- elsif !ownerDocument.nil?
- doc = ownerDocument
- else
- return nil
- end
- ids = doc._getIDAttrs
- end
- if nodeType == ELEMENT_NODE && _getIDVals(ids).include?(value)
- return self
- elsif !@children.nil?
- @children.each do |node|
- if !(match = node._searchID(value, ids)).nil?
- return match
- end
- end
- end
- return nil
- end
-
- def _getMyLocation(parent)
- index = parent._getChildIndex(self)
- if !index.nil?
- "child(#{index + 1},#all)"
- else
- nil
- end
- end
-
-=begin
- --- Node#makeXPointer(use_id = true)
-
-return XPointer's expression of this node.
-=end
- def makeXPointer(use_id = true)
- if use_id && !attributes.nil? && !(idvals = _getIDVals).empty?
- "id(#{idvals[0]})"
- elsif @parent.nil? || @parent.nodeType == DOCUMENT_NODE
- "root()"
- else
- @parent.makeXPointer(use_id) + "." + self._getMyLocation(@parent)
- end
- end
-
- ## [Masaki Fukushima]
- def _child(reverse = false)
- return if @children.nil?
- @children.reversible_each(reverse) do |child|
- yield child
- end
- end
-
- ## [Masaki Fukushima]
- def _descendant(reverse = false)
- return if @children.nil?
- @children.reversible_each(reverse) do |child|
- yield child
- child._descendant(reverse) do |node|
- yield node
- end
- end
- end
-
- ## [Masaki Fukushima]
- def _ancestor(reverse = false)
- return if @parent.nil?
- yield @parent if !reverse
- @parent._ancestor(reverse) do |node| yield node end
- yield @parent if reverse
- end
-
- ## [Masaki Fukushima]
- def __sibling(reverse, only_appeared_before_self)
- return if @parent.nil?
- self_appeared = false
- @parent.childNodes.reversible_each(reverse) do |node|
- if node == self
- self_appeared = true
- next
- end
- if only_appeared_before_self
- break if self_appeared
- yield node
- else # only appeared after self
- yield node if self_appeared
- end
- end
- end
-
- ## [Masaki Fukushima]
- def _psibling(reverse = false)
- __sibling(!reverse, reverse) do |sib|
- yield sib
- end
- end
-
- ## [Masaki Fukushima]
- def _fsibling(reverse = false)
- __sibling(reverse, reverse) do |sib|
- yield sib
- end
- end
-
- ## [Masaki Fukushima]
- def _preceding(reverse = false)
- return if @parent.nil?
- prev_sib = previousSibling
- if prev_sib
- prev_sib._preceding(reverse) {|node| yield node} if reverse
- yield prev_sib
- prev_sib._descendant(!reverse) {|node| yield node}
- prev_sib._preceding(reverse) {|node| yield node} if !reverse
- else
- @parent._preceding(reverse) {|node| yield node} if reverse
- yield @parent
- @parent._preceding(reverse) {|node| yield node} if !reverse
- end
- end
-
- ## [Masaki Fukushima]
- def _following(reverse = false)
- return if @parent.nil?
- next_sib = nextSibling
- if next_sib
- next_sib._following(reverse) {|node| yield node} if reverse
- yield next_sib
- next_sib._descendant(reverse) {|node| yield node}
- next_sib._following(reverse) {|node| yield node} if !reverse
- else
- @parent._following(reverse) {|node| yield node} if reverse
- yield @parent
- @parent._following(reverse) {|node| yield node} if !reverse
- end
- end
-
- ## [Masaki Fukushima]
- def _matchAttribute?(attr, value)
- case value
- when '*'
- return !attr.nil?
- when '#IMPLIED'
- return attr.nil?
- else
- return false if attr.nil?
- end
-
- case value
- when /^"([^"]*)"$/, /^'([^']*)'$/
- ignore_case = false
- value = $1
- when Spec::Name
- ignore_case = true
- else
- raise "invalid attribute value: #{value}"
- end
- if ignore_case
- return attr.nodeValue.downcase == value.downcase
- else
- return attr.nodeValue == value
- end
- end
-
- ## [Masaki Fukushima]
- def _matchNodeAttributes?(node, attributes)
- return true if attributes.nil?
- raise TypeError if !attributes.is_a?(Hash)
- return true if attributes.length == 0
- return false if node.nodeType != ELEMENT_NODE
-
- attributes.each do |name, value|
- case name
- when '*'
- return catch(:match) {
- node.attributes.each do |attr|
- throw(:match, true) if _matchAttribute?(attr, value)
- end
- false
- }
- when Spec::Name
- attr = node.attributes[name] unless node.attributes.nil?
- return _matchAttribute?(attr, value)
- else
- raise "invalid attribute name: '#{name}'"
- end
- end
- end
-
- ## [Masaki Fukushima]
- def _matchNodeType?(node, ntype)
- case ntype
- when '#element'
- return (node.nodeType == ELEMENT_NODE)
- when '#pi'
- return (node.nodeType == PROCESSING_INSTRUCTION_NODE)
- when '#comment'
- return (node.nodeType == COMMENT_NODE)
- when '#text'
- return (node.nodeType == TEXT_NODE ||
- node.nodeType == CDATA_SECTION_NODE)
- when '#cdata'
- return (node.nodeType == CDATA_SECTION_NODE)
- when '#all'
- case node.nodeType
- when ELEMENT_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE,
- TEXT_NODE, CDATA_SECTION_NODE
- return true
- else
- return false
- end
- when /^#/
- raise "unknown node type: '#{ntype}'"
- when Spec::Name
- return (node.nodeType == ELEMENT_NODE && node.nodeName == ntype)
- else
- raise "invalid element type: '#{ntype}'"
- end
- end
-
- ## [Masaki Fukushima]
- def _matchNode?(node, ntype, attributes)
- _matchNodeType?(node, ntype) &&
- _matchNodeAttributes?(node, attributes)
- end
-
- ## [Masaki Fukushima]
- def _nodesByRelativeLocationTerm(location)
- if location !~ /^([a-z]+)\(([^\)]*)\)$/
- raise "invalid relative location: '#{location}'"
- end
- keyword = $1
- args = $2.split(/,/)
- number = args.shift
- ntype = args.shift
- ntype = '#element' if ntype.nil?
- attributes = args
-
- reverse = false
- # check instance number
- case number
- when nil, ''
- raise "missing instance number: '#{location}'"
- when 'all'
- when Spec::Instance
- number = number.to_i
- if number < 0
- reverse = true
- number = -number
- end
- else
- raise "unknown instance number: '#{number}'"
- end
-
- # check attributes
- if attributes.length % 2 != 0
- raise " missing attribute value: '#{location}'"
- end
- attributes = Hash[*attributes]
-
- # iterate over nodes specified with keyword
- i = 0
- self.send("_#{keyword}", reverse) do |node|
- next unless _matchNode?(node, ntype, attributes)
- if number == "all"
- yield node
- else
- i += 1
- if i >= number
- yield node
- break
- end
- end
- end
- end
-
- ## [Masaki Fukushima]
- def _nodesByLocationTerms(location, pre_keyword = nil)
- if location !~ /^([a-z]*)\(([^)]*)\)(\.(.+))?$/
- raise "invalid location: \"#{location}\""
- end
- keyword = $1
- args = $2
- rest = $4
- ## omitted keyword
- keyword = pre_keyword if keyword == ''
- if keyword.nil?
- raise "cannot determine preceding keyword: \"#{location}\""
- end
-
- case keyword
- when 'child', 'descendant', 'ancestor', 'psibling', 'fsibling',
- 'preceding', 'following'
- # relative location term
- _nodesByRelativeLocationTerm("#{keyword}(#{args})") do |node|
- if rest.nil?
- yield node
- else
- node._nodesByLocationTerms(rest, keyword) do |n|
- yield n
- end
- end
- end
- when 'attr'
- # attribute location term
- if args !~ Spec::Name
- raise "invalid attribute name: '#{args}'"
- end
- attr = attributes[args]
- value = (attr.nil? ? nil : Text.new(attr.nodeValue))
- if rest.nil?
- yield value
- elsif !value.nil?
- value._nodesByLocationTerms(rest) do |node|
- yield node
- end
- end
- when 'span', 'string'
- raise "unsupported keyword: '#{keyword}'"
- else
- raise "unknown keyword: '#{keyword}'"
- end
- end
-
- ## [Masaki Fukushima]
- def _getNodeByAbsoluteLocationTerm(location)
- case location
- when 'root()', ''
- if nodeType == DOCUMENT_NODE
- root = documentElement
- elsif !ownerDocument.nil?
- root = ownerDocument.documentElement
- end
- root = self if root.nil?
- return root
- when 'origin()'
- return self
- when /^id\(([^\)]*)\)$/
- value = $1
- raise "invalid id value: #{value}" if value !~ Spec::Name
- return _searchID(value)
- when /^html\(([^\)]*)\)$/
- value = $1
- return getNodesByXPointer("root().descendant(1,A,NAME,\"#{value}\")")[0]
- else
- raise "unknown keyword: #{location}"
- end
- end
-
-=begin
- --- Node#getNodeByXPointer(pointer)
-
-return node indicated by the XPointer pointer.
-=end
- ## [Masaki Fukushima]
- def getNodesByXPointer(pointer)
- if pointer !~ /^([a-z]+)\(([^)]*)\)(\.(.+))?$/
- raise "invalid XPointer: \"#{pointer}\""
- end
- keyword = $1
- args = $2
- rest = $4
-
- case keyword
- when 'root', 'origin', 'id', 'html'
- src = _getNodeByAbsoluteLocationTerm("#{keyword}(#{args})")
- else
- src = _getNodeByAbsoluteLocationTerm("root()")
- rest = pointer
- end
-
- ret = NodeList.new
- if src.nil?
- # no match
- elsif rest.nil?
- yield src if iterator?
- ret << src
- else
- src._nodesByLocationTerms(rest) do |node|
- yield node if iterator?
- ret << node
- end
- end
- ret
- end
-
-=begin
- --- Node#ownerDocument()
-
-[DOM]
-Document object associated with this node.
-=end
- ## [DOM]
- ## Floating objects are not owned by any documents.
- def ownerDocument
- return @ownerDocument if @ownerDocument
- parent = self.parentNode
- return nil if parent.nil?
- if parent.nodeType == DOCUMENT_NODE
- return parent
- else
- return parent.ownerDocument
- end
- end
-
- def ownerDocument=(document); @ownerDocument = document; end
-
-
-=begin
- --- Node#cloneNode()
-
-[DOM]
-return the copy of the Node.
-=end
- ## [DOM]
- def cloneNode(deep = true, *args)
- ret = self.class.new(*args)
- if (deep)
- @children.each do |child|
- ret.appendChild(child.cloneNode(true))
- end
- end if @children
- ret
- end
-
-=begin
- --- Node#trim(preserve = false)
-
-trim extra whitespaces.
-=end
- ## trim extra whitespaces
- ## if attribute 'xml:space' is 'preserve',
- ## don't trim any white spaces
- def trim(preserve = false)
- return nil if @children.nil?
- children = @children.to_a.dup
- children.each do |child|
- if !preserve && (child.nodeType == TEXT_NODE ||
- child.nodeType == CDATA_SECTION_NODE)
- if child.trim == ""
- self.removeChild(child)
- end
- else
- child.trim(preserve)
- end
- end
- nil
- end
-
-
- end
-
-=begin
-== Class XML::DOM::NamedNodeMap
-
-=end
-
- class NamedNodeMap
-
-=begin
-=== Class Methods
-
- --- NamedNodeMap.new(nodes = nil)
-
-creates a new NamedNodeMap.
-=end
- def initialize(nodes = nil)
- @nodes = {}
- nodes.each do |node|
- @nodes[node.nodeName] = node
- end if nodes
- end
-
-=begin
-=== Methods
-
- --- NamedNodeMap#getNamedItem(name)
-
-[DOM]
-retrieves a node specified by name.
-=end
- ## [DOM]
- def getNamedItem(name)
- @nodes[name]
- end
-
-=begin
- --- NamedNodeMap#setNamedItem(node)
-
-[DOM]
-adds a node using its nodeName attribute.
-=end
- ## [DOM]
- def setNamedItem(node)
- @nodes[node.nodeName] = node
- end
-
-=begin
- --- NamedNodeMap#removeNamedItem(name)
-
-[DOM]
-removes a node specified by name.
-=end
- ## [DOM]
- def removeNamedItem(name)
- ret = @nodes[name]
- @nodes[name] = nil
- ret
- end
-
-=begin
- --- NamedNodeMap#item(index)
-
-[DOM]
-returns the index item in the map.
-=end
- ## [DOM]
- def item(index)
- v = @nodes.to_a[index]
- return v[1] if v
- nil
- end
-
-=begin
- --- NamedNodeMap#[](name)
-
-returns nodes associated to name.
-=end
- def [](name)
- @nodes[name]
- end
-
-=begin
- --- NamedNodeMap#[]=(name, node)
-
-sets node named name.
-=end
- def []=(name, node)
- raise "parameter error" if node.nodeName != name
- @nodes[name] = node
- end
-
-=begin
- --- NamedNodeMap#each()
-
-iterates over each pair of name and node(name, node) of the namedNodeMap.
-=end
- def each
- @nodes.each do |key, value|
- yield(value)
- end
- end
-
-=begin
- --- NamedNodeMap#size()
-
-[DOM]
-returns the number of nodes in the map.
-=end
- ## [DOM]
- def size
- @nodes.length
- end
- alias length size
-
- ## get nodeValues by names
- ## names ::= name ('|' name)*
- def _getValues(names)
- ret = []
- names.split('|').each do |name|
- if !@nodes[name].nil?
- ret.push(@nodes[name].nodeValue)
- end
- end
- ret
- end
- end
-
-=begin
-== Class XML::DOM::NodeList
-
-
-=end
- class NodeList
-
-=begin
-=== Class Methods
-
- --- NodeList.new(nodes = nil)
-
-creates a new NodeList.
-=end
- def initialize(nodes = nil)
- if nodes.nil?
- @nodes = []
- elsif nodes.is_a?(Array)
- @nodes = nodes
- else
- raise "parameter error"
- end
- end
-
-=begin
-=== Methods
-
- --- NodeList#item(index)
-
-[DOM]
-return the indexth item in the NodeList.
-=end
- ## [DOM]
- def item(index)
- @nodes[index]
- end
-
-=begin
- --- NodeList#size()
-
-return size of NodeList.
-=end
- def size
- @nodes.length
- end
- alias length size
-
-=begin
- --- NodeList#[](index)
-
-return indexth node of the NodeList.
-=end
- def [](index)
- @nodes[index]
- end
-
-=begin
- --- NodeList#[]=(*p)
-
-set node of indexth node of the NodeList.
-=end
- def []=(*p)
- if p.length == 2
- @nodes[p[0]] = p[1]
- elsif p.length == 3
- @nodes[p[0], p[1]] = p[2]
- end
- end
-
-=begin
- --- NodeList#each
-
-iterates over each node of the NodeList.
-=end
- def each
- @nodes.each do |value|
- yield(value)
- end
- end
-
-=begin
- --- NodeList#reversible_each(reverse = false)
-
-iterates over each node of the reversed NodeList.
-=end
- ## [Masaki Fukushima]
- def reversible_each(reverse = false)
- if !reverse
- @nodes.each do |value|
- yield(value)
- end
- else
- @nodes.reverse_each do |value|
- yield(value)
- end
- end
- end
-
-=begin
- --- NodeList#push(*nodes)
-
-adds nodes into the NodeList.
-=end
- def push(*nodes)
- nodes.each do |node|
- if node.is_a?(Array)
- self.push(*node)
- elsif node.is_a?(NodeList)
- @nodes.concat(node.to_a)
- elsif node.is_a?(Node)
- @nodes << node
- else
- raise "parameter error"
- end
- end
- self
- end
-
-=begin
- --- NodeList#concat(*nodes)
-
-alias of NodeList#push.
-=end
- alias concat push
-
-=begin
- --- NodeList#pop
-
-pops and returns the last node of the NodeList.
-=end
- def pop
- @nodes.pop
- end
-
-=begin
- --- NodeList#shift
-
-removes and returns the first node of the NodeList.
-=end
- def shift
- @nodes.shift
- end
-
-=begin
- --- NodeList#to_s
-
-returns the string representation of the NodeList.
-=end
- def to_s
- @nodes.to_s
- end
-
-=begin
- --- NodeList#reverse
-
-returns the reversed NodeList.
-=end
- def reverse
- @nodes.reverse
- end
-
-=begin
- --- NodeList#to_a
-
-converts the NodeList into an array.
-=end
- def to_a
- @nodes
- end
-
-=begin
- --- NodeList#+(nodes)
-
-return the newly created concatenated NodeList.
-=end
- def +(nodes)
- if nodes.nil?
- NodeList.new(@nodes)
- elsif nodes.is_a?(Array)
- NodeList.new(@nodes + nodes)
- elsif nodes.is_a?(NodeList)
- NodeList.new(@nodes + nodes.to_a)
- elsif nodes.is_a?(Node)
- NodeList.new(@nodes + [nodes])
- else
- raise "parameter error"
- end
- end
-
-=begin
- --- NodeList#<<(nodes)
-
-appends nodes to the NodeList.
-=end
- ## modified by Masaki Fukushima
- def <<(nodes)
- if nodes.nil?
- ## no change
- elsif nodes.is_a?(Array)
- @nodes.concat(nodes)
- elsif nodes.is_a?(NodeList)
- @nodes.concat(nodes.to_a)
- elsif nodes.is_a?(Node)
- @nodes << nodes
- else
- raise "parameter error"
- end
- self
- end
-
- ## get nodeValues by names
- ## names ::= name ('|' name)*
- def _getValues(names)
- ret = []
- names.split('|').each do |name|
- if !@nodes[name].nil?
- ret.push(@nodes[name].nodeValue)
- end
- end
- ret
- end
- end
-
-=begin
-== Class XML::DOM::DocumentFragment
-
-=== superclass
-Node
-
-=end
- class DocumentFragment<Node
-
-=begin
-=== Class Methods
-
- --- DocumentFragment.new(*children)
-
-creates a new DocumentFragment.
-=end
-
- def initialize(*children)
- super(*children)
- end
-
-=begin
-=== Methods
-
- --- DocumentFragment#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- DOCUMENT_FRAGMENT_NODE
- end
-
-=begin
- --- DocumentFragment#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- "#document-fragment"
- end
-
-=begin
- --- DocumentFragment#parentNode=(p)
-
-returns the parent of this node.
-=end
- ## DocumentFragment should not have the parent node.
- def parentNode=(p)
- @children.each do |child|
- child.parentNode = p
- end if @children
- end
-
- def _checkNode(node)
- unless node.nodeType == ELEMENT_NODE ||
- node.nodeType == PROCESSING_INSTRUCTION_NODE ||
- node.nodeType == COMMENT_NODE ||
- node.nodeType == TEXT_NODE ||
- node.nodeType == CDATA_SECTION_NODE ||
- node.nodeType == ENTITY_REFERENCE_NODE
- raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
- end
- end
-
- end
-
-=begin
-== Class XML::DOM::Document
-
-=== superclass
-Node
-
-=end
- class Document<Node
-=begin
-=== Class Methods
- --- Document.new(*children)
-
-creates a new Document.
-=end
-
- ## new([child1, child2, ...]) or
- ## new(child1, child2, ...)
- ## child?: String or Node
- def initialize(*children)
- super(*children)
- end
-
-=begin
-=== Methods
-
- --- Document#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- DOCUMENT_NODE
- end
-
-=begin
- --- Document#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- "#document"
- end
-
-=begin
- --- Document#documentElement
-
-[DOM]
-returns root element of the Docuemnt.
-=end
- ## [DOM]
- def documentElement
- @children.each do |child|
- if child.nodeType == ELEMENT_NODE
- return child
- end
- end if @children
- nil
- end
-
-=begin
- --- Document#doctype
-
-[DOM]
-returns DTD associated with this document.
-=end
- ## [DOM]
- def doctype
- @children.each do |child|
- if child.nodeType == DOCUMENT_TYPE_NODE
- return child
- end
- end if @children
- nil
- end
-
-=begin
- --- Document#getElementsByTagName(tagname)
-
-[DOM]
-returns a NodeList of all the Elements with a given tag name.
-=end
- ## [DOM] (but this is not "live")
- 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
-
-=begin
- --- Document#createElement(tagName)
-
-[DOM]
-creates a Element.
-=end
- ## [DOM]
- def createElement(tagName)
- ret = Element.new(tagName)
- ret.ownerDocument = self
- ret
- end
-
-=begin
- --- Document#createTextNode(data)
-
-[DOM]
-creates a TextNode.
-=end
- ## [DOM]
- def createTextNode(data)
- ret = Text.new(data)
- ret.ownerDocument = self
- ret
- end
-
-=begin
- --- Document#createCDATASection(data)
-
-[DOM]
-creates a CDATASection.
-=end
- ## [DOM]
- def createCDATASection(data)
- ret = CDATASection.new(data)
- ret.ownerDocument = self
- ret
- end
-
-=begin
- --- Document#createComment(data)
-
-[DOM]
-create a Comment.
-=end
- ## [DOM]
- def createComment(data)
- ret = Comment.new(data)
- ret.ownerDocument = self
- ret
- end
-
-=begin
- --- Document#createProcessingInstruction(target, data)
-
-[DOM]
-create a ProcessingInstruction.
-=end
- ## [DOM]
- def createProcessingInstruction(target, data)
- ret = ProcessingInstruction.new(target, data)
- ret.ownerDocument = self
- ret
- end
-
-=begin
- --- Document#createAttribute(name)
-
-[DOM]
-create a Attribute.
-=end
- ## [DOM]
- def createAttribute(name)
- ret = Attr.new(name)
- ret.ownerDocument = self
- ret
- end
-
-=begin
- --- Document#createEntityReference(name)
-
-[DOM]
-create a EntityReference.
-=end
- ## [DOM]
- def createEntityReference(name)
- ret = EntityReference.new(name)
- ret.ownerDocument = self
- ret
- end
-
-=begin
- --- Document#createDocumentFragment()
-
-[DOM]
-create a DocumentFragment.
-=end
- ## [DOM]
- def createDocumentFragment
- ret = DocumentFragment.new
- ret.ownerDocument = self
- ret
- end
-
- ## set the ID list by the attribute name with the element name
- ## (or wildcard)
- ## [experimental implement]
- def _setIDAttr(attrname, elemname = '*')
- @idattrs = {} if @idattrs.nil?
- @idattrs[elemname] = attrname
- end
-
- ## get the ID list
- ## [experimental implement]
- def _getIDAttrs
- return {'*'=>'id'} if @idattrs.nil?
- @idattrs
- end
-
- ## [DOM]
- def implementation
- return @implemantation if @implemantation
- ## singleton
- @implemantation = DOMImplementation.instance
- end
-
- def implementation=(impl)
- @implemantation = impl
- end
-
- 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
-
- end
-
-=begin
-== Class XML::DOM::Attr
-
-=== superclass
-Node
-
-=end
- class Attr<Node
- ## new(name, [text1, text2, ...]) or
- ## new(name, text1, text2, ...)
- ## name: String
- ## text?: String or Node
-
-=begin
-=== Class Methods
-
- --- Attr.new(name = nil, *text)
-
-create a new Attr.
-=end
- def initialize(name = nil, *text)
- super(text)
- raise "parameter error" if !name
- @name = name
- @name.freeze
- end
-
-=begin
-=== Methods
-
- --- Attr#nodeType()
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- ATTRIBUTE_NODE
- end
-
-=begin
- --- Attr#nodeName()
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- @name
- end
-
-=begin
- --- Attr#nodeValue()
-
-[DOM]
-returns the nodeValue.
-=end
- ## [DOM]
- def nodeValue
- ret = ""
- @children.each do |child|
- ret << child.nodeValue
- end if @children
- ret
- end
-
-=begin
- --- Attr#nodeValue=(text)
-
-[DOM]
-returns the value of this node.
-=end
- ## [DOM]
- def nodeValue=(text)
- self.childNodes = [text]
- end
-
-=begin
- --- Attr#to_s()
-
-return the string representation of the Attr.
-=end
- def to_s
- value = ""
- nodeValue.each_byte do |code|
- case code
- when 9, 10, 13
- value << sprintf("&#x%X;", code)
- when ?&
- value << "&"
- when ?"
- value << """
- when ?<
- value << "<"
- else
- value << code
- end
- end
- "#{@name}=\"#{value}\""
- end
-
-=begin
- --- Attr#dump(depth = 0)
-
-dump the Attr.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print "// #{self.to_s}\n"
- end
-
-=begin
- --- Attr#cloneNode(deep = true)
-
-[DOM]
-returns the copy of the Attr.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- super(deep, @name)
- end
-
-=begin
- --- Attr#name()
-
-[DOM]
-alias of nodeName.
-=end
- ## [DOM]
- alias name nodeName
-
-=begin
- --- Attr#value()
-
-alias of nodeValue.
-
- --- Attr#value=(value)
-
-[DOM]
-alias of nodeValue=.
-=end
- ## [DOM]
- alias value nodeValue
- alias value= nodeValue=
-
- ## [DOM]
- def specified; @specified; end
- def specified=(is_specified); @specified = is_specified; end
-
- def _checkNode(node)
- unless node.nodeType == TEXT_NODE ||
- node.nodeType == ENTITY_REFERENCE_NODE
- raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
- end
- end
-
- end
-
-=begin
-== Class XML::DOM::Attribute
-
-alias of Attr.
-=end
- Attribute = Attr
-
-=begin
-== Class XML::DOM::Element
-
-=== superclass
-Node
-
-=end
- class Element<Node
-
-=begin
-=== Class Methods
-
- --- Element.new(tag = nil, attrs = nil, *children)
-
-create a new Element.
-=end
- ## new(tag, attrs, [child1, child2, ...]) or
- ## new(tag, attrs, child1, child2, ...)
- ## tag: String
- ## attrs: Hash, Attr or Array of Attr (or nil)
- ## child?: String or Node
- def initialize(tag = nil, attr = nil, *children)
- super(*children)
- raise "parameter error" if !tag
- @name = tag.freeze
- if attr.nil?
- @attr = NamedNodeMap.new([])
- elsif attr.is_a?(Hash)
- nodes = []
- attr.each do |key, value|
- nodes.push(Attr.new(key, value))
- end
- @attr = NamedNodeMap.new(nodes)
- elsif attr.is_a?(Array)
- @attr = NamedNodeMap.new(attr)
- elsif attr.is_a?(Attr)
- @attr = NamedNodeMap.new([attr])
- else
- raise "parameter error: #{attr}"
- end
- end
-
-=begin
-=== Methods
-
- --- Element#nodeType()
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- ELEMENT_NODE
- end
-
-=begin
- --- Element#nodeName()
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- @name
- end
-
-=begin
- --- Element#attributes()
-
-[DOM]
-returns the attributes of this Element.
-=end
- ## [DOM]
- def attributes
- if iterator?
- @attr.each do |key, value|
- yield(value)
- end if @attr
- else
- @attr
- end
- end
-
-=begin
- --- Element#to_s()
-
-return the string representation of the Element.
-=end
- def to_s
- attr = ''
- @attr.each do |a|
- attr << ' ' + a.to_s
- end if @attr
- content = super
- if content != ''
- ret = "<#{@name}#{attr}>#{content}</#{@name}>"
- else
- ret = "<#{@name}#{attr}/>"
- end
- ret << "\n" if parentNode.nodeType == DOCUMENT_NODE
- ret
- end
-
-=begin
- --- Element#dump(depth = 0)
-
-dumps the Element.
-=end
- def dump(depth = 0)
- attr = ''
- @attr.each do |a| ## self.attributes do |a|
- attr += a.to_s + ", "
- end if @attr
- attr.chop!
- attr.chop!
- print ' ' * depth * 2
- print "#{@name}(#{attr})\n"
- @children.each do |child|
- child.dump(depth + 1)
- end if @children
- end
-
-=begin
- --- Element#tagName()
-
-[DOM]
-alias of nodeName.
-=end
- ## [DOM]
- alias tagName nodeName
-
-=begin
- --- Element#getAttribute(name)
-
-[DOM]
-retrieves an attribute value by name.
-=end
- ## [DOM]
- def getAttribute(name)
- attr = getAttributeNode(name)
- if attr.nil?
- ''
- else
- attr.nodeValue
- end
- end
-
-=begin
- --- Element#setAttribute(name, value)
-
-[DOM]
-adds a new attribute.
-=end
- ## [DOM]
- def setAttribute(name, value)
- if @ownerDocument
- attr = @ownerDocument.createAttribute(name)
- attr.appendChild(@ownerDocument.createTextNode(value))
- else
- attr = Attribute.new(name)
- attr.appendChild(Text.new(value))
- end
- setAttributeNode(attr)
- end
-
-=begin
- --- Element#removeAttribute(name)
-
-[DOM]
-remove an attribute by name.
-=end
- ## [DOM]
- def removeAttribute(name)
- ret = getAttributeNode(name)
- removeAttributeNode(ret) if ret
- end
-
-=begin
- --- Element#getAttributeNode(name)
-
-[DOM]
-retrieves an Attr node by name.
-=end
- ## [DOM]
- def getAttributeNode(name)
- @attr.getNamedItem(name)
- end
-
-=begin
- --- Element#setAttributeNode(newAttr)
-
-[DOM]
-adds a new attribute.
-=end
- ## [DOM]
- def setAttributeNode(newAttr)
- ret = getAttributeNode(newAttr.nodeName)
- if ret == newAttr
- raise DOMException.new(DOMException::INUSE_ATTRIBUTE_ERR)
- end
- @attr.setNamedItem(newAttr)
- ret
- end
-
-=begin
- --- Element#removeAttributeNode(oldAttr)
-
-[DOM]
-removes the specified attribute.
-=end
- ## [DOM]
- def removeAttributeNode(oldAttr)
- ret = getAttributeNode(oldAttr.nodeName)
- if ret.nil? || ret != oldAttr
- raise DOMException.new(DOMException::NOT_FOUND_ERR)
- end
- @attr.removeNamedItem(oldAttr.nodeName)
- ret
- end
-
-=begin
- --- Element#getElementsByTagName(tagname)
-
-[DOM]
-returns a NodeList of all descendant elements with given tag name.
-=end
- ## [DOM] (but this is not "live")
- 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
-
- def _getMyLocation(parent)
- index = 1
- parent.childNodes do |child|
- if child == self
- return "child(#{index},#{@name})"
- end
- if child.nodeType == ELEMENT_NODE && child.nodeName == @name
- index += 1
- end
- end
- nil
- end
-
-
-=begin
- --- Element#normalize
-
-[DOM]
-puts all Text nodes in the full depth of the sub-tree under this
-Eelemnt.
-=end
- ## [DOM]
- def normalize
- return if @children.nil?
- old = nil
- children = @children.to_a.dup
- children.each do |child|
- if !old.nil? && old.nodeType == TEXT_NODE &&
- child.nodeType == TEXT_NODE
- old.appendData(child.nodeValue)
- self.removeChild(child)
- else
- if child.nodeType == ELEMENT_NODE
- child.normalize
- end
- old = child
- end
- end
- end
-
-=begin
- --- Element#cloneNode(deep = true)
-
-[DOM]
-returns the copy of the Element.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- attrs = []
- @attr.each do |attr|
- attrs.push(attr.cloneNode(true))
- end
- super(deep, @name, attrs)
- end
-
- ## get the list of nodeValues by IDs
- ## [experimental implement]
- def _getIDVals(ids = nil)
- if ids.nil?
- doc = ownerDocument
- return [] if doc.nil?
- ids = doc._getIDAttrs
- end
-
- idelem = []
- if !ids[nodeName].nil?
- return attributes._getValues(ids[nodeName])
- elsif !ids['*'].nil?
- return attributes._getValues(ids['*'])
- end
- return []
- end
-
-=begin
- --- Element#trim(preserve = false)
-
-trim extra whitespaces.
-=end
- ## trim extra whitespaces
- ## if attribute 'xml:space' is 'preserve',
- ## don't trim any white spaces
- def trim(preserve = false)
- if !attributes['xml:space'].nil?
- value = attributes['xml:space'].nodeValue
- if value == 'preserve'
- preserve = true
- elsif value == 'default'
- preserve = false
- end
- end
- return nil if @children.nil?
- children = @children.to_a.dup
- children.each do |child|
- if !preserve && (child.nodeType == TEXT_NODE ||
- child.nodeType == CDATA_SECTION_NODE)
- if child.trim == ""
- self.removeChild(child)
- end
- else
- child.trim(preserve)
- end
- end
- nil
- end
-
- def _checkNode(node)
- unless node.nodeType == ELEMENT_NODE ||
- node.nodeType == TEXT_NODE ||
- node.nodeType == COMMENT_NODE ||
- node.nodeType == PROCESSING_INSTRUCTION_NODE ||
- node.nodeType == CDATA_SECTION_NODE ||
- node.nodeType == ENTITY_REFERENCE_NODE
- raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
- end
- end
-
- end
-
-=begin
-== Class XML::DOM::CharacterData
-
-=== superclass
-Node
-
-=end
- class CharacterData<Node
-
-=begin
-=== Class Methods
-
- --- CharacterData.new(text)
-
-creates a new CharacterData.
-=end
- ## new(text)
- ## text: String
- def initialize(text = nil)
- super()
- raise "parameter error" if !text
- @value = text
- end
-
-=begin
-=== Methods
-
- --- CharacterData#data()
-
-[DOM]
-returns the character data of the node.
-=end
- ## [DOM]
- def data
- @value.dup
- end
-
-=begin
- --- CharacterData#data=(p)
-
-[DOM]
-set the character data of the node.
-=end
- ## [DOM]
- def data=(p)
- @value = p
- end
-
-=begin
- --- CharacterData#length()
-
-[DOM]
-returns length of this CharacterData.
-=end
- ## [DOM]
- def length
- @value.length
- end
-
-=begin
- --- CharacterData#substringData(start, count)
-
-[DOM]
-extracts a range of data from the node.
-=end
- ## [DOM]
- def substringData(start, count)
- if start < 0 || start > @value.length || count < 0
- raise DOMException.new(DOMException::INDEX_SIZE_ERR)
- end
- ## if the sum of start and count > length,
- ## return all characters to the end of the value.
- @value[start, count]
- end
-
-=begin
- --- CharacterData#appendData(str)
-
-[DOM]
-append the string to the end of the character data.
-=end
- ## [DOM]
- def appendData(str)
- @value << str
- end
-
-=begin
- --- CharacterData#insertData(offset, str)
-
-[DOM]
-insert a string at the specified character offset.
-=end
- ## [DOM]
- def insertData(offset, str)
- if offset < 0 || offset > @value.length
- raise DOMException.new(DOMException::INDEX_SIZE_ERR)
- end
- @value[offset, 0] = str
- end
-
-=begin
- --- CharacterData#deleteData(offset, count)
-
-[DOM]
-removes a range of characters from the node.
-=end
- ## [DOM]
- def deleteData(offset, count)
- if offset < 0 || offset > @value.length || count < 0
- raise DOMException.new(DOMException::INDEX_SIZE_ERR)
- end
- @value[offset, count] = ''
- end
-
-=begin
- --- CharacterData#replaceData(offset, count, str)
-
-[DOM]
-replaces the characters starting at the specified character offset
-with specified string.
-=end
- ## [DOM]
- def replaceData(offset, count, str)
- if offset < 0 || offset > @value.length || count < 0
- raise DOMException.new(DOMException::INDEX_SIZE_ERR)
- end
- @value[offset, count] = str
- end
-
-=begin
- --- CharacterData#cloneData(deep = true)
-
-[DOM]
-returns the copy of the CharacterData.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- super(deep, @value.dup)
- end
-
-=begin
- --- Text#nodeValue
-
-[DOM]
-return nodevalue.
-
-=end
- ## [DOM]
- def nodeValue
- @value
- end
-
-=begin
- --- CharacterData#nodeValue=(p)
-
-[DOM]
-set nodevalue as p.
-=end
- ## [DOM]
- def nodeValue=(p)
- @value = p
- end
-
- end
-
-=begin
-== Class XML::DOM::Text
-
-=== superclass
-Node
-
-=end
- class Text<CharacterData
-
-=begin
-=== Class Methods
-
- --- Text.new(text)
-
-creates a new Text.
-=end
- ## new(text)
- ## text: String
- def initialize(text = nil)
- super(text)
- end
-
-=begin
-=== Methods
-
- --- Text#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- TEXT_NODE
- end
-
-=begin
- --- Text#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- "#text"
- end
-
-=begin
- --- Text#to_s
-
-return the string representation of the Text.
-=end
- def to_s
- ret = ""
- @value.each_byte do |code|
- case (code)
- when 13
- ret << sprintf("&#x%X;", code)
- when ?&
- ret << "&"
- when ?<
- ret << "<"
- when ?>
- ret << ">"
- else
- ret << code
- end
- end
- ret
- end
-
-=begin
- --- Text#dump(depth = 0)
-
-dumps the Text.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print "#{@value.inspect}\n"
- end
-
- def _getMyLocation(parent)
- index = 1
- parent.childNodes do |child|
- if child == self
- return "child(#{index},#text)"
- end
- if child.nodeType == TEXT_NODE
- index += 1
- end
- end
- nil
- end
-
-=begin
- --- Text#splitText(offset)
-
-[DOM]
-breaks this Text node into two Text nodes at the specified offset.
-=end
- ## [DOM]
- def splitText(offset)
- if offset > @value.length || offset < 0
- raise DOMException.new(DOMException::INDEX_SIZE_ERR)
- end
- newText = @value[offset, @value.length]
- newNode = Text.new(newText)
- if !self.parentNode.nil?
- self.parentNode.insertAfter(newNode, self)
- end
- @value[offset, @value.length] = ""
- newNode
- end
-
-=begin
- --- Text#trim(preserve = false)
-
-trim extra whitespaces.
-=end
- def trim(preserve = false)
- if !preserve
- @value.sub!(/\A\s*([\s\S]*?)\s*\Z/, "\\1")
- return @value
- end
- nil
- end
-
- end
-
-=begin
-== Class XML::DOM::Comment
-
-=== superclass
-CharacterData
-
-=end
- class Comment<CharacterData
-
-=begin
-=== Class Methods
-
- --- Comment.new(text)
-
-creates a new Comment.
-=end
- ## new(text)
- ## text: String
- def initialize(text = nil)
- super(text)
- raise "parameter error" if !text
- end
-
-=begin
-=== Methods
-
- --- Comment#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- COMMENT_NODE
- end
-
-=begin
- --- Comment#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- "#comment"
- end
-
-=begin
- --- Comment#to_s
-
-returns the string representation of the Comment.
-=end
- def to_s
- ret = "<!--#{@value}-->"
- ret << "\n" if parentNode.nodeType == DOCUMENT_NODE
- ret
- end
-
-=begin
- --- Comment#dump(depth =0)
-
-dumps the Comment.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print "<!--#{@value.inspect}-->\n"
- end
-
- def _getMyLocation(parent)
- index = 1
- parent.childNodes do |child|
- if child == self
- return "child(#{index},#comment)"
- end
- if child.nodeType == COMMENT_NODE
- index += 1
- end
- end
- nil
- end
- end
-
-
- ## Extended Interfaces
-
-=begin
-== Class XML::DOM::CDATASection
-
-=== superclass
-Text
-
-=end
- class CDATASection<Text
-=begin
-=== Class Methods
-
- --- CDATASection.new(text = nil)
-
-creates a new CDATASection.
-=end
- def initialize(text = nil)
- super(text)
- raise "parameter error" if !text
- end
-
-=begin
-=== Methods
-
- --- CDATASection#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- CDATA_SECTION_NODE
- end
-
-=begin
- --- CDATASection#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- "#cdata-section"
- end
-
-=begin
- --- CDATASection#to_s
-
-returns the string representation of the CDATASection.
-=end
- def to_s
- "<![CDATA[#{@value}]]>"
- end
-
-=begin
- --- CDATASection#dump(depth = 0)
-
-dumps the CDATASection.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print "<![CDATA[#{@value.inspect}]]>\n"
- end
-
- def _getMyLocation(parent)
- index = 1
- parent.childNodes do |child|
- if child == self
- return "child(#{index},#cdata)"
- end
- if child.nodeType == CDATA_SECTION_NODE
- index += 1
- end
- end
- nil
- end
- end
-
-=begin
-== Class XML::DOM::DocumentType
-
-=== superclass
-Node
-=end
- class DocumentType<Node
-
-=begin
-=== Class Methods
-
- --- DocumentType.new(name, value = nil, *children)
-
-creates a new DocuemntType.
-=end
- def initialize(name, value = nil, *children)
- super(*children)
- raise "parameter error" if !name
- @name = name.freeze
- @value = value.freeze
- end
-
-=begin
-=== Methods
-
- --- DocumentType#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- DOCUMENT_TYPE_NODE
- end
-
-=begin
- --- DocumentType#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- @name
- end
-
-=begin
- --- DocumentType#to_s
-
-returns the string representation of the DocumentType.
-=end
- def to_s
- ret = "<!DOCTYPE " + @name
- if !@value.nil?
- ret <<= " " + @value
- end
- if !@children.nil? && @children.length > 0
- ret <<= " [\n"
- @children.each do |child|
- if child.nodeType == PROCESSING_INSTRUCTION_NODE ||
- child.nodeType == COMMENT_NODE
- ret <<= child.to_s + "\n"
- else
- ret <<= child.nodeValue + "\n"
- end
- end
- ret <<= "]"
- end
- ret <<= ">"
- end
-
-=begin
- --- DocumentType#dump(depth = 0)
-
-dumps the DocumentType.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print "<!DOCTYPE #{@name} #{@value} [\n"
- @children.each do |child|
- print ' ' * (depth + 1) * 2
- if child.nodeType == PROCESSING_INSTRUCTION_NODE ||
- child.nodeType == COMMENT_NODE
- child.dump
- else
- print child.nodeValue, "\n"
- end
- end if @children
- print ' ' * depth * 2
- print "]>\n"
- end
-
-=begin
- --- DocumentType#cloneNode(deep = true)
-
-[DOM]
-returns the copy of the DocumentType.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- super(deep, @name, @value)
- end
-
- ## [DOM]
- ## def entities; @entities; end
- ## def notations; @notations; end
- end
-
-=begin
-== Class XML::DOM::Notation
-
-=== superclass
-Node
-=end
- class Notation<Node
-=begin
-=== Class Methods
-
- --- Notation.new(name, pubid, sysid)
-
-creates a new Notation.
-=end
- def initialize(name, pubid, sysid)
- super()
- @name = name.freeze
- @pubid = pubid.freeze
- @sysid = sysid.freeze
- end
-
-=begin
-=== Methods
-
- --- Notation#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- NOTATION_NODE
- end
-
-=begin
- --- Notation#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- @name
- end
-
-=begin
- --- Notation#publicId
-
-returns the publicId of the Notation.
-=end
- def publicId
- @pubid
- end
-
-=begin
- --- Notation#systemId
-
-returns the systemId of the Notation.
-=end
- def systemId
- @sysid
- end
-
-=begin
- --- Notation#cloneNode(deep = true)
-
-[DOM]
-returns the copy of the Notation.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- super(deep, @name, @pubid, @sysid)
- end
- end
-
-=begin
-== Class XML::DOM::Entity
-
-=== superclass
-Node
-=end
- class Entity<Node
-
-=begin
-=== Class Methods
-
- --- Entity.new(name, pubid, sysid, notation)
-
-creates a new Entity.
-=end
- def initialize(name, pubid, sysid, notation)
- super()
- @name = name.freeze
- @pubid = pubid.freeze
- @sysid = sysid.freeze
- @notation = notation.freeze
- end
-
-=begin
-=== Methods
-
- --- Entity#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- ENTITY_NODE
- end
-
-=begin
- --- Entity#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- @name
- end
-
-=begin
- --- Entity#publicId
-
-returns the publicId of the Entity.
-=end
- def publicId
- @pubid
- end
-
-=begin
- --- Entity#systemId
-
-returns the systemId of the Entity.
-=end
- def systemId
- @sysid
- end
-
-=begin
- --- Entity#notationName
-
-returns the notationname of the Entity.
-=end
- def notationName
- @notation
- end
-
-=begin
- --- Entity#cloneNode(deep = true)
-
-[DOM]
-returns the copy of the Entity.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- super(deep, @name, @pubid, @sysid, @notation)
- end
-
- def _checkNode(node)
- unless node.nodeType == ELEMENT_NODE ||
- node.nodeType == PROCESSING_INSTRUCTION_NODE ||
- node.nodeType == COMMENT_NODE ||
- node.nodeType == TEXT_NODE ||
- node.nodeType == CDATA_SECTION_NODE ||
- node.nodeType == ENTITY_REFERENCE_NODE
- raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
- end
- end
-
- end
-
-=begin
-== Class XML::DOM::EntityReference
-
-=== superclass
-Node
-=end
- class EntityReference<Node
-
-=begin
-=== Class Methods
-
- --- EntityReference.new(name, *children)
-
-creates a new EntityReference.
-=end
- def initialize(name, *children)
- super(*children)
- raise "parameter error" if !name
- @name = name.freeze
- end
-
-=begin
-=== Methods
-
- --- EntityReference#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- ENTITY_REFERENCE_NODE
- end
-
-=begin
- --- EntityReference#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- @name
- end
-
-=begin
- --- EntityReference#to_s
-
-returns the string representation of the EntityReference.
-=end
- ## reference form or expanded form?
- def to_s
- "&#{@name};"
- end
-
-=begin
- --- EntityReference#dump(depth = 0)
-
-dumps the EntityReference.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print "&#{@name}{\n"
- @children.each do |child|
- child.dump(depth + 1)
- end if @children
- print ' ' * depth * 2
- print "}\n"
- end
-
-=begin
- --- EntityReference#cloneNode(deep = true)
-
-[DOM]
-returns the copy of the EntityReference.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- super(deep, @name)
- end
-
- def _checkNode(node)
- unless node.nodeType == ELEMENT_NODE ||
- node.nodeType == PROCESSING_INSTRUCTION_NODE ||
- node.nodeType == COMMENT_NODE ||
- node.nodeType == TEXT_NODE ||
- node.nodeType == CDATA_SECTION_NODE ||
- node.nodeType == ENTITY_REFERENCE_NODE
- raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
- end
- end
-
- end
-
-=begin
-== Class XML::DOM::ProcessingInstruction
-
-=== superclass
-Node
-
-=end
- class ProcessingInstruction<Node
-
-=begin
-=== Class Methods
-
- --- ProcessingInstruction.new(target = nil, data = nil)
-
-creates a new ProcessingInstruction.
-=end
- ## new(target, data)
- ## target: String
- ## data: String
- def initialize(target = nil, data = nil)
- super()
- raise "parameter error" if !data
- @target = target.freeze
- @data = data.freeze
- @value = target.dup
- @value << " #{data}" if data != ""
- @value.freeze
- end
-
-=begin
-=== Methods
-
- --- ProcessingInstruction#nodeType
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- PROCESSING_INSTRUCTION_NODE
- end
-
-=begin
- --- ProcessingInstruction#nodeName
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- "#proccessing-instruction"
- end
-
-=begin
- --- ProcessingInstruction#target
-
-[DOM]
-returns the target of the ProcessingInstruction.
-=end
- ## [DOM]
- def target
- @target
- end
-
-=begin
- --- ProcessingInstruction#target=(p)
-
-[DOM]
-set p to the target of the ProcessingInstruction.
-=end
- ## [DOM]
- def target=(p)
- @target = p.freeze
- @value = @target.dup
- @value << " #{@data}" if @data != ""
- @value.freeze
- end
-
-=begin
- --- ProcessingInstruction#data
-
-[DOM]
-return the content of the ProcessingInstruction.
-=end
- ## [DOM]
- def data
- @data
- end
-
-=begin
- --- ProcessingInstruction#data=(p)
-
-[DOM]
-sets p to the content of the ProcessingInstruction.
-=end
- ## [DOM]
- def data=(p)
- @data = p.freeze
- @value = @target.dup
- @value << " #{@data}" if @data != ""
- @value.freeze
- end
-
-=begin
- --- ProcessingInstruction#nodeValue
-
-[DOM]
-return nodevalue.
-
-=end
- ## [DOM]
- def nodeValue
- @value
- end
-
- ## inhibit changing value without target= or data=
- undef nodeValue=
-
-=begin
- --- ProcessingInstruction#to_s
-
-returns the string representation of the ProcessingInstruction.
-=end
- def to_s
- ret = "<?#{@value}?>"
- ret << "\n" if parentNode.nodeType == DOCUMENT_NODE
- ret
- end
-
-=begin
- --- ProcessingInstruction#dump(depth = 0)
-
-dumps the ProcessingInstruction.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print "<?#{@value.inspect}?>\n"
- end
-
- def _getMyLocation(parent)
- index = 1
- parent.childNodes do |child|
- if child == self
- return "child(#{index},#pi)"
- end
- if child.nodeType == PROCESSING_INSTRUCTION_NODE
- index += 1
- end
- end
- nil
- end
-
-=begin
- --- ProcessingInstruction#cloneNode(deep = true)
-
-[DOM]
-returns the copy of the ProcessingInstruction.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- super(deep, @target.dup, @data.dup)
- end
- end
-
- end
-
- SimpleTree = DOM
-
-end
diff --git a/.pc/replaces_gt_symbol_by_enconded_version.patch/lib/xml/dom2/attr.rb b/.pc/replaces_gt_symbol_by_enconded_version.patch/lib/xml/dom2/attr.rb
deleted file mode 100644
index 53bb911..0000000
--- a/.pc/replaces_gt_symbol_by_enconded_version.patch/lib/xml/dom2/attr.rb
+++ /dev/null
@@ -1,213 +0,0 @@
-## -*- Ruby -*-
-## XML::DOM
-## 1998-2001 by yoshidam
-##
-
-require 'xml/dom2/node'
-require 'xml/dom2/domexception'
-
-module XML
- module DOM
-
-=begin
-== Class XML::DOM::Attr
-
-=== superclass
-Node
-
-=end
- class Attr<Node
- ## new(name, [text1, text2, ...]) or
- ## new(name, text1, text2, ...)
- ## name: String
- ## text?: String or Node
-
-=begin
-=== Class Methods
-
- --- Attr.new(name = nil, *text)
-
-create a new Attr.
-=end
- def initialize(name, *text)
- super(text)
- raise "parameter error" if !name
- @name = nil
- @prefix = nil
- @localname = nil
- @uri = nil
- @ownerElement = nil
- if name.is_a?(Array)
- ## namespaces
- raise "parameter error" if name.length != 2
- @localname = name[1]
- if name[1].index(':')
- @prefix, @localname = name[1].split(':')
- end
- @name = name[1] ## qualified name
- @uri = name[0] ## namespace URI
- else
- @name = name
- end
- @name.freeze
- @prefix.freeze
- @localname.freeze
- @uri.freeze
- end
-
-=begin
-=== Methods
-
- --- Attr#nodeType()
-
-[DOM]
-returns the nodeType.
-=end
- ## [DOM]
- def nodeType
- ATTRIBUTE_NODE
- end
-
-=begin
- --- Attr#nodeName()
-
-[DOM]
-returns the nodeName.
-=end
- ## [DOM]
- def nodeName
- @name
- end
-
-=begin
- --- Attr#nodeValue()
-
-[DOM]
-returns the nodeValue.
-=end
- ## [DOM]
- def nodeValue
- ret = ""
- @children.each do |child|
- ret << child.nodeValue
- end if @children
- ret
- end
-
-=begin
- --- Attr#nodeValue=(text)
-
-[DOM]
-returns the value of this node.
-=end
- ## [DOM]
- def nodeValue=(text)
- self.childNodes = [text]
- end
-
-=begin
- --- Attr#to_s()
-
-return the string representation of the Attr.
-=end
- def to_s
- value = ""
- nodeValue.scan(/./um) do |c|
- code = c.unpack("U")[0]
- if code == 9 || code == 10 || code == 13
- value << sprintf("&#x%X;", code)
- elsif c == "&"
- value << "&"
- elsif c == "\""
- value << """
- elsif c == "<"
- value << "<"
- else
- value << c
- end
- end
- "#{@name}=\"#{value}\""
- end
-
-=begin
- --- Attr#dump(depth = 0)
-
-dump the Attr.
-=end
- def dump(depth = 0)
- print ' ' * depth * 2
- print "// #{self.to_s}\n"
- end
-
-=begin
- --- Attr#cloneNode(deep = true)
-
-[DOM]
-returns the copy of the Attr.
-=end
- ## [DOM]
- def cloneNode(deep = true)
- super(deep, @name)
- end
-
-=begin
- --- Attr#name()
-
-[DOM]
-alias of nodeName.
-=end
- ## [DOM]
- alias name nodeName
-
-=begin
- --- Attr#value()
-
-alias of nodeValue.
-
- --- Attr#value=(value)
-
-[DOM]
-alias of nodeValue=.
-=end
- ## [DOM]
- alias value nodeValue
- alias value= nodeValue= ##
-
- ## [DOM]
- def specified; @specified; end
- def specified=(is_specified); @specified = is_specified; end
-
- ## [DOM2]
- def namespaceURI; @uri; end
-
- ## [DOM2]
- def prefix; @prefix; end
-
- ## [DOM2]
- def prefix=(prefix);
- ## to be checked
-
- @ownerElement.removeAttributeNode(self) if @ownerElement
- @prefix = prefix
- @name = @prefix + ':' + @localname
- @ownerElement.setAttributeNode(self) if @ownerElement
- @prefix.freeze
- @name.freeze
- end
-
- ## [DOM2]
- def localname; @localname; end
-
- ## [DOM2]
- def ownerElement; @ownerElement; end
- def ownerElement=(elem); @ownerElement = elem; end
-
- def _checkNode(node)
- unless node.nodeType == TEXT_NODE ||
- node.nodeType == ENTITY_REFERENCE_NODE
- raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
- end
- end
- end
- end
-end
diff --git a/ext/encoding.h b/ext/encoding.h
deleted file mode 100644
index 4e0374b..0000000
--- a/ext/encoding.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*****************************************************************
-** encoding.h
-**
-** Copyright 1998 Clark Cooper
-** All rights reserved.
-**
-** This program is free software; you can redistribute it and/or
-** modify it under the same terms as Perl itself.
-*/
-
-#ifndef ENCODING_H
-#define ENCODING_H 1
-
-#define ENCMAP_MAGIC 0xfeebface
-
-typedef struct prefixmap {
- unsigned char min;
- unsigned char len; /* 0 => 256 */
- unsigned short bmap_start;
- unsigned char ispfx[32];
- unsigned char ischar[32];
-} PrefixMap;
-
-typedef struct encinf
-{
- unsigned short prefixes_size;
- unsigned short bytemap_size;
- int firstmap[256];
- PrefixMap *prefixes;
- unsigned short *bytemap;
-} Encinfo;
-
-typedef struct encmaphdr
-{
- unsigned int magic;
- char name[40];
- unsigned short pfsize;
- unsigned short bmsize;
- int map[256];
-} Encmap_Header;
-
-/*================================================================
-** Structure of Encoding map binary encoding
-**
-** Note that all shorts and ints are in network order,
-** so when packing or unpacking with perl, use 'n' and 'N' respectively.
-** In C, use the htonl family of functions.
-**
-** The basic structure is:
-**
-** _______________________
-** |Header (including map expat needs for 1st byte)
-** |PrefixMap * pfsize
-** | This section isn't included for single-byte encodings.
-** | For multiple byte encodings, when a byte represents a prefix
-** | then it indexes into this vector instead of mapping to a
-** | Unicode character. The PrefixMap type is declared above. The
-** | ispfx and ischar fields are bitvectors indicating whether
-** | the byte being mapped is a prefix or character respectively.
-** | If neither is set, then the character is not mapped to Unicode.
-** |
-** | The min field is the 1st byte mapped for this prefix; the
-** | len field is the number of bytes mapped; and bmap_start is
-** | the starting index of the map for this prefix in the overall
-** | map (next section).
-** |unsigned short * bmsize
-** | This section also is omitted for single-byte encodings.
-** | Each short is either a Unicode scalar or an index into the
-** | PrefixMap vector.
-**
-** The header for these files is declared above as the Encmap_Header type.
-** The magic field is a magic number which should match the ENCMAP_MAGIC
-** macro above. The next 40 bytes stores IANA registered name for the
-** encoding. The pfsize field holds the number of PrefixMaps, which should
-** be zero for single byte encodings. The bmsize field holds the number of
-** shorts used for the overall map.
-**
-** The map field contains either the Unicode scalar encoded by the 1st byte
-** or -n where n is the number of bytes that such a 1st byte implies (Expat
-** requires that the number of bytes to encode a character is indicated by
-** the 1st byte) or -1 if the byte doesn't map to any Unicode character.
-**
-** If the encoding is a multiple byte encoding, then there will be PrefixMap
-** and character map sections. The 1st PrefixMap (index 0), covers a range
-** of bytes that includes all 1st byte prefixes.
-**
-** Look at convert_to_unicode in Expat.xs to see how this data structure
-** is used.
-*/
-
-#endif /* ndef ENCODING_H */
diff --git a/ext/extconf.rb b/ext/extconf.rb
deleted file mode 100644
index 4432b9f..0000000
--- a/ext/extconf.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# ruby extconf.rb
-# --with-perl-enc-map[=/path/to/enc-map]
-# --with-expat-dir=/path/to/expat
-# --with-expat-lib=/path/to/expat/lib
-# --with-expat-include=/path/to/expat/include
-#
-require 'mkmf'
-
-cwd=`pwd`.chomp!
-perl= ENV['PERL'] || 'perl'
-
-## Encoding maps may be stored in $perl_archlib/XML/Parser/Encodins/
-#perl_archlib = '/usr/lib/perl5/site_perl/5.005/i586-linux'
-#perl_archlib = '/usr/local/lib'
-perl_archlib = `#{perl} -e 'use Config; print $Config{"archlib"}'`
-xml_enc_path = with_config("perl-enc-map")
-if xml_enc_path == true
- xml_enc_path = perl_archlib + "/XML/Parser/Encodings"
-end
-
-##$CFLAGS="-I#{cwd}/expat/xmlparse -I#{cwd}/expat/xmltok" +
-## ' -DXML_ENC_PATH=getenv\(\"XML_ENC_PATH\"\)' +
-## " -DNEW_EXPAT"
-#$CFLAGS = "-I#{cwd}/expat/xmlparse -I#{cwd}/expat/xmltok"
-#$LDFLAGS = "-L#{cwd}/expat/xmlparse -Wl,-rpath,/usr/local/lib"
-#$LDFLAGS = "-L#{cwd}/expat/xmlparse"
-dir_config("expat")
-#dir_config("xmltok")
-#dir_config("xmlparse")
-if xml_enc_path
- $CFLAGS += " -DXML_ENC_PATH=\\\"#{xml_enc_path}\\\""
-end
-
-#if have_header("xmlparse.h") || have_header("expat.h")
-if have_header("expat.h") || have_header("xmlparse.h")
- if have_library("expat", "XML_ParserCreate") ||
- have_library("xmltok", "XML_ParserCreate")
- if have_func("XML_SetNotStandaloneHandler")
- $CFLAGS += " -DNEW_EXPAT"
- end
- if have_func("XML_SetParamEntityParsing")
- $CFLAGS += " -DXML_DTD"
- end
-# if have_func("XML_SetExternalParsedEntityDeclHandler")
-# $CFLAGS += " -DEXPAT_1_2"
-# end
- have_func("XML_SetDoctypeDeclHandler")
- have_func("XML_ParserReset")
- have_func("XML_SetSkippedEntityHandler")
- have_func("XML_GetFeatureList")
- have_func("XML_UseForeignDTD")
- have_func("XML_GetIdAttributeIndex")
- have_library("socket", "ntohl")
- have_library("wsock32") if RUBY_PLATFORM =~ /mswin32|mingw/
- create_makefile("xmlparser")
- end
-end
diff --git a/ext/xmlparser.c b/ext/xmlparser.c
deleted file mode 100644
index aa32d11..0000000
--- a/ext/xmlparser.c
+++ /dev/null
@@ -1,2292 +0,0 @@
-/*
- * Expat (XML Parser Toolkit) wrapper for Ruby
- * Dec 15, 2009 yoshidam version 0.7.0 support Ruby 1.9.1
- * Feb 16, 2004 yoshidam version 0.6.8 taint output string
- * Feb 16, 2004 yoshidam version 0.6.7 fix buffer overflow
- * Mar 11, 2003 yoshidam version 0.6.6 fix skippedEntity handler
- * Sep 20, 2002 yoshidam version 0.6.5 fix reset method
- * Apr 4, 2002 yoshidam version 0.6.3 change event code values
- * Oct 10, 2000 yoshidam version 0.6.1 support expat-1.2
- * Oct 6, 2000 yoshidam version 0.6.0 support expat-1.95.0
- * Jun 28, 1999 yoshidam version 0.5.18 define initialize for Ruby 1.5
- * Jun 28, 1999 yoshidam version 0.5.15 support start/endDoctypeDecl
- * Jun 28, 1999 yoshidam version 0.5.14 support setParamEntityParsing
- * Apr 28, 1999 yoshidam version 0.5.11 support notStandalone
- * Mar 29, 1998 yoshidam version 0.5.9 optimize for Ruby 1.3
- * Mar 8, 1998 yoshidam version 0.5.7 support start/endNamespaceDecl
- * Jan 14, 1998 yoshidam version 0.5.4 support start/endCdataSection
- * Jan 10, 1998 yoshidam version 0.5.3 support encoding map
- * Nov 24, 1998 yoshidam version 0.5.0 support TEST version of expat
- * Nov 5, 1998 yoshidam version 0.4.18 mIDs are initialized in Init_xmlparser
- * Oct 28, 1998 yoshidam version 0.4.17 mIDs are stored into static vars
- * Oct 13, 1998 yoshidam version 0.4.12 debug and speed up myEncodingConv
- * Oct 7, 1998 yoshidam version 0.4.11 hold internal object into ivar
- * Sep 18, 1998 yoshidam version 0.4.6
- * Sep 8, 1998 yoshidam version 0.4.4
- * Sep 3, 1998 yoshidam version 0.4.3
- * Sep 1, 1998 yoshidam version 0.4.2
- * Aug 28, 1998 yoshidam version 0.4.1
- * Aug 22, 1998 yoshidam version 0.4.0
- * Jul 6, 1998 yoshidam version 0.2
- * Jun 30, 1998 yoshidam version 0.1
- *
- * XML_ENC_PATH: path of encoding map for Perl
- * HAVE_XML_USEFOREIGNDTD: expat 1.95.5
- * HAVE_XML_GETFEATURELIST: expat 1.95.5
- * HAVE_XML_SETSKIPPEDENTITYHANDLER: expat 1.95.4
- * HAVE_XML_PARSERRESET: expat 1.95.3
- * HAVE_EXPAT_H: expat 1.95.0
- * HAVE_XML_SETDOCTYPEDECLHANDLER: expat 19990728
- * XML_DTD: expat 19990626
- * NEW_EXPAT: expat 1.1
- */
-
-#include "ruby.h"
-#ifdef HAVE_RUBY_IO_H
-# include "ruby/io.h"
-#else
-# include "rubyio.h"
-#endif
-#include <stdio.h>
-#include <ctype.h>
-#ifdef HAVE_EXPAT_H
-# include "expat.h"
-#else
-# include "xmlparse.h"
-#endif
-#ifdef XML_ENC_PATH
-# include <limits.h>
-# include <sys/stat.h>
-# include "encoding.h"
-# ifndef PATH_MAX
-# define PATH_MAX 256
-# endif
-#endif
-
-#ifndef RSTRING_PTR
-# define RSTRING_PTR(s) (RSTRING(s)->ptr)
-# define RSTRING_LEN(s) (RSTRING(s)->len)
-#endif
-
-#ifdef HAVE_RUBY_ENCODING_H
-static rb_encoding* enc_xml;
-#endif
-
-static VALUE eXMLParserError;
-static VALUE cXMLParser;
-static VALUE cXMLEncoding;
-static ID id_map;
-static ID id_startElementHandler;
-static ID id_endElementHandler;
-static ID id_characterDataHandler;
-static ID id_processingInstructionHandler;
-static ID id_defaultHandler;
-static ID id_defaultExpandHandler;
-static ID id_unparsedEntityDeclHandler;
-static ID id_notationDeclHandler;
-static ID id_externalEntityRefHandler;
-static ID id_unknownEncoding;
-static ID id_convert;
-#ifdef NEW_EXPAT
-static ID id_commentHandler;
-static ID id_startCdataSectionHandler;
-static ID id_endCdataSectionHandler;
-static ID id_startNamespaceDeclHandler;
-static ID id_endNamespaceDeclHandler;
-static ID id_notStandaloneHandler;
-#endif
-#ifdef HAVE_XML_SETDOCTYPEDECLHANDLER
-static ID id_startDoctypeDeclHandler;
-static ID id_endDoctypeDeclHandler;
-#endif
-#ifdef HAVE_EXPAT_H
-static ID id_elementDeclHandler;
-static ID id_attlistDeclHandler;
-static ID id_xmlDeclHandler;
-static ID id_entityDeclHandler;
-#endif
-#if 0
-static ID id_externalParsedEntityDeclHandler;
-static ID id_internalParsedEntityDeclHandler;
-#endif
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
-static ID id_skippedEntityHandler;
-#endif
-
-#define GET_PARSER(obj, parser) \
- Data_Get_Struct(obj, XMLParser, parser)
-
-typedef struct _XMLParser {
- XML_Parser parser;
- int iterator;
- int defaultCurrent;
-#ifdef NEW_EXPAT
- const XML_Char** lastAttrs;
-#endif
- int tainted;
- VALUE parent;
- char* context;
- const XML_Char *detectedEncoding;
-} XMLParser;
-
-static VALUE symDEFAULT;
-static VALUE symSTART_ELEM;
-static VALUE symEND_ELEM;
-static VALUE symCDATA;
-static VALUE symPI;
-static VALUE symUNPARSED_ENTITY_DECL;
-static VALUE symNOTATION_DECL;
-static VALUE symEXTERNAL_ENTITY_REF;
-#ifdef NEW_EXPAT
-static VALUE symCOMMENT;
-static VALUE symSTART_CDATA;
-static VALUE symEND_CDATA;
-static VALUE symSTART_NAMESPACE_DECL;
-static VALUE symEND_NAMESPACE_DECL;
-#endif
-#ifdef HAVE_XML_SETDOCTYPEDECLHANDLER
-static VALUE symSTART_DOCTYPE_DECL;
-static VALUE symEND_DOCTYPE_DECL;
-#endif
-#ifdef HAVE_EXPAT_H
-static VALUE symELEMENT_DECL;
-static VALUE symATTLIST_DECL;
-static VALUE symXML_DECL;
-static VALUE symENTITY_DECL;
-#endif
-#if 0
-static VALUE symEXTERNAL_PARSED_ENTITY_DECL;
-static VALUE symINTERNAL_PARSED_ENTITY_DECL;
-#endif
-#if 0
-static VALUE symUNKNOWN_ENCODING;
-#endif
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
-static VALUE symSKIPPED_ENTITY;
-#endif
-
-/* destructor */
-static void
-XMLParser_free(XMLParser* parser)
-{
- /* fprintf(stderr, "Delete XMLParser: %p->%p\n", parser, parser->parser);*/
- if (parser->parser) {
- XML_ParserFree(parser->parser);
- parser->parser = NULL;
- }
- free(parser);
-}
-
-static void
-XMLParser_mark(XMLParser* parser)
-{
- /* fprintf(stderr, "Mark XMLParser: %p->%p\n", parser, parser->parser);*/
- if (!NIL_P(parser->parent)) {
- XMLParser* parent;
- GET_PARSER(parser->parent, parent);
- rb_gc_mark(parser->parent);
- }
-}
-
-static void
-taintParser(XMLParser* parser) {
- parser->tainted |= 1;
- if (!NIL_P(parser->parent) && !parser->context) {
- XMLParser* parent;
- GET_PARSER(parser->parent, parent);
- taintParser(parent);
- }
-}
-
-inline static VALUE
-taintObject(XMLParser* parser, VALUE obj) {
- if (parser->tainted)
- OBJ_TAINT(obj);
- return obj;
-}
-#define TO_(o) (taintObject(parser, o))
-
-inline static VALUE
-freezeObject(VALUE obj) {
- OBJ_FREEZE(obj);
- return obj;
-}
-#define FO_(o) (freezeObject(o))
-
-#ifdef HAVE_RUBY_ENCODING_H
-# define ENC_(o) (rb_enc_associate(o, enc_xml))
-#else
-# define ENC_(o) (o)
-#endif
-
-
-/* Event handlers for iterator */
-static void
-iterStartElementHandler(void *recv,
- const XML_Char *name, const XML_Char **atts)
-{
- XMLParser* parser;
- VALUE attrhash;
-
- GET_PARSER(recv, parser);
-#ifdef NEW_EXPAT
- parser->lastAttrs = atts;
-#endif
- attrhash = rb_hash_new();
- while (*atts) {
- const char* key = *atts++;
- const char* val = *atts++;
- rb_hash_aset(attrhash,
- FO_(TO_(ENC_(rb_str_new2((char*)key)))),
- TO_(ENC_(rb_str_new2((char*)val))));
- }
-
- rb_yield(rb_ary_new3(4, symSTART_ELEM,
- TO_(ENC_(rb_str_new2((char*)name))), attrhash, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterEndElementHandler(void *recv,
- const XML_Char *name)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symEND_ELEM,
- TO_(ENC_(rb_str_new2((char*)name))), Qnil, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterCharacterDataHandler(void *recv,
- const XML_Char *s,
- int len)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symCDATA,
- Qnil, TO_(ENC_(rb_str_new((char*)s, len))), recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterProcessingInstructionHandler(void *recv,
- const XML_Char *target,
- const XML_Char *data)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symPI,
- TO_(ENC_(rb_str_new2((char*)target))),
- TO_(ENC_(rb_str_new2((char*)data))), recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterDefaultHandler(void *recv,
- const XML_Char *s,
- int len)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symDEFAULT,
- Qnil, TO_(ENC_(rb_str_new((char*)s, len))), recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- /* XML_DefaultCurrent shoould not call in defaultHandler */
- /* XML_DefaultCurrent(parser->parser); */
- }
-}
-
-void
-iterUnparsedEntityDeclHandler(void *recv,
- const XML_Char *entityName,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId,
- const XML_Char *notationName)
-{
- XMLParser* parser;
- VALUE valary;
-
- GET_PARSER(recv, parser);
- valary = rb_ary_new3(4, (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- TO_(ENC_(rb_str_new2((char*)systemId))),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil),
- TO_(ENC_(rb_str_new2((char*)notationName))));
- rb_yield(rb_ary_new3(4, symUNPARSED_ENTITY_DECL,
- TO_(ENC_(rb_str_new2((char*)entityName))),
- valary, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-void
-iterNotationDeclHandler(void *recv,
- const XML_Char *notationName,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId)
-{
- XMLParser* parser;
- VALUE valary;
-
- GET_PARSER(recv, parser);
- valary = rb_ary_new3(3,
- (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- (systemId ? TO_(ENC_(rb_str_new2((char*)systemId))) : Qnil),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil));
- rb_yield(rb_ary_new3(4, symNOTATION_DECL,
- TO_(ENC_(rb_str_new2((char*)notationName))),
- valary, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-int
-iterExternalEntityRefHandler(XML_Parser xmlparser,
- const XML_Char *context,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId)
-{
- XMLParser* parser;
- VALUE recv;
- VALUE valary;
- VALUE ret;
-
- recv = (VALUE)XML_GetUserData(xmlparser);
- GET_PARSER(recv, parser);
- valary = rb_ary_new3(3,
- (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- (systemId ? TO_(ENC_(rb_str_new2((char*)systemId))) : Qnil),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil));
- ret = rb_yield(rb_ary_new3(4, symEXTERNAL_ENTITY_REF,
- (context ? TO_(ENC_(rb_str_new2((char*)context))) : Qnil),
- valary, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
- /* The error status in this iterator block should be returned
- by the exception. */
- return 1;
-}
-
-#ifdef NEW_EXPAT
-static void
-iterCommentHandler(void *recv,
- const XML_Char *s)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symCOMMENT,
- Qnil, TO_(ENC_(rb_str_new2((char*)s))), recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterStartCdataSectionHandler(void *recv)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symSTART_CDATA, Qnil, Qnil, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterEndCdataSectionHandler(void *recv)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symEND_CDATA, Qnil, Qnil, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterStartNamespaceDeclHandler(void *recv,
- const XML_Char *prefix,
- const XML_Char *uri)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symSTART_NAMESPACE_DECL,
- (prefix ? TO_(ENC_(rb_str_new2((char*)prefix))) : Qnil),
- (uri ? TO_(ENC_(rb_str_new2((char*)uri))) : Qnil), recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterEndNamespaceDeclHandler(void *recv,
- const XML_Char *prefix)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symEND_NAMESPACE_DECL,
- (prefix ? TO_(ENC_(rb_str_new2((char*)prefix))) : Qnil),
- Qnil, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-#endif
-
-#ifdef HAVE_XML_SETPARAMENTITYPARSING
-static void
-#ifdef HAVE_EXPAT_H
-iterStartDoctypeDeclHandler(void *recv,
- const XML_Char *doctypeName,
- const XML_Char *sysid,
- const XML_Char *pubid,
- int has_internal_subset)
-#else
-iterStartDoctypeDeclHandler(void *recv,
- const XML_Char *doctypeName)
-#endif
-{
- XMLParser* parser;
- VALUE valary = Qnil;
-
- GET_PARSER(recv, parser);
-#ifdef HAVE_EXPAT_H
- valary = rb_ary_new3(3,
- (sysid ? TO_(ENC_(rb_str_new2((char*)sysid))) : Qnil),
- (pubid ? TO_(ENC_(rb_str_new2((char*)pubid))) : Qnil),
- (has_internal_subset ? Qtrue : Qfalse));
-#endif
- rb_yield(rb_ary_new3(4, symSTART_DOCTYPE_DECL,
- TO_(ENC_(rb_str_new2((char*)doctypeName))),
- valary, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterEndDoctypeDeclHandler(void *recv)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symEND_DOCTYPE_DECL,
- Qnil,
- Qnil, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-#endif
-
-
-#ifdef HAVE_EXPAT_H
-
-static VALUE
-makeContentArray(XMLParser* parser, XML_Content* model)
-{
- static const char* content_type_name[] = {
- NULL, "EMPTY", "ANY", "MIXED", "NAME", "CHOICE", "SEQ"
- };
- static const char* content_quant_name[] = {
- "", "?", "*", "+"
- };
- unsigned int i;
- VALUE children = Qnil;
- const char* type_name = content_type_name[model->type];
- const char* quant_name = content_quant_name[model->quant];
- VALUE ret = rb_ary_new3(3,
- TO_(ENC_(rb_str_new2((char*)type_name))),
- TO_(ENC_(rb_str_new2((char*)quant_name))),
- (model->name ? TO_(ENC_(rb_str_new2((char*)model->name))) :
- Qnil));
- if (model->numchildren > 0) {
- children = rb_ary_new();
- for (i = 0; i < model->numchildren; i++) {
- VALUE child = makeContentArray(parser, model->children + i);
- rb_ary_push(children, child);
- }
- }
- rb_ary_push(ret, children);
- return ret;
-}
-
-
-
-static void
-iterElementDeclHandler(void *recv,
- const XML_Char *name,
- XML_Content *model)
-{
- XMLParser* parser;
- VALUE content;
- GET_PARSER(recv, parser);
- content = makeContentArray(parser, model);
- rb_yield(rb_ary_new3(4, symELEMENT_DECL,
- TO_(ENC_(rb_str_new2(name))),
- content, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterAttlistDeclHandler (void *recv,
- const XML_Char *elname,
- const XML_Char *attname,
- const XML_Char *att_type,
- const XML_Char *dflt,
- int isrequired)
-{
- XMLParser* parser;
- VALUE valary;
-
- GET_PARSER(recv, parser);
- valary = rb_ary_new3(4,
- TO_(ENC_(rb_str_new2((char*)attname))),
- TO_(ENC_(rb_str_new2((char*)att_type))),
- (dflt ? TO_(ENC_(rb_str_new2((char*)dflt))) : Qnil),
- (isrequired ? Qtrue : Qfalse));
- rb_yield(rb_ary_new3(4, symATTLIST_DECL,
- TO_(ENC_(rb_str_new2(elname))),
- valary, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterXmlDeclHandler (void *recv,
- const XML_Char *version,
- const XML_Char *encoding,
- int standalone)
-{
- XMLParser* parser;
- VALUE valary;
-
- GET_PARSER(recv, parser);
- valary = rb_ary_new3(3,
- (version ? TO_(ENC_(rb_str_new2(version))) : Qnil),
- (encoding ? TO_(ENC_(rb_str_new2((char*)encoding))) : Qnil),
- INT2FIX(standalone));
- rb_yield(rb_ary_new3(4, symXML_DECL,
- Qnil,
- valary, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterEntityDeclHandler (void *recv,
- const XML_Char *entityName,
- int is_parameter_entity,
- const XML_Char *value,
- int value_length,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId,
- const XML_Char *notationName)
-{
- XMLParser* parser;
- VALUE valary;
-
- GET_PARSER(recv, parser);
- valary = rb_ary_new3(6,
- (is_parameter_entity ? Qtrue : Qfalse),
- TO_(ENC_(rb_str_new((char*)value, value_length))),
- (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- (systemId ? TO_(ENC_(rb_str_new2((char*)systemId))) : Qnil),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil),
- (notationName ? TO_(ENC_(rb_str_new2((char*)notationName)))
- : Qnil));
- rb_yield(rb_ary_new3(4, symENTITY_DECL,
- TO_(ENC_(rb_str_new2(entityName))),
- valary, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-#endif
-
-#if 0
-static void
-iterExternalParsedEntityDeclHandler(void *recv,
- const XML_Char *entityName,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId)
-{
- XMLParser* parser;
- VALUE valary;
-
- GET_PARSER(recv, parser);
- valary = rb_ary_new3(3, (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- TO_(ENC_(rb_str_new2((char*)systemId))),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil));
- rb_yield(rb_ary_new3(4, symEXTERNAL_PARSED_ENTITY_DECL,
- TO_(ENC_(rb_str_new2((char*)entityName))),
- valary, recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-
-static void
-iterInternalParsedEntityDeclHandler(void *recv,
- const XML_Char *entityName,
- const XML_Char *replacementText,
- int replacementTextLength)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symINTERNAL_PARSED_ENTITY_DECL,
- TO_(ENC_(rb_str_new2((char*)entityName))),
- TO_(ENC_(rb_str_new((char*)replacementText,
- replacementTextLength))), recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-#endif
-
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
-static void
-iterSkippedEntityHandler(void *recv,
- const XML_Char *entityName,
- int is_parameter_entity)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_yield(rb_ary_new3(4, symSKIPPED_ENTITY,
- TO_(ENC_(rb_str_new2((char*)entityName))),
- INT2FIX(is_parameter_entity), recv));
- if (parser->defaultCurrent) {
- parser->defaultCurrent = 0;
- XML_DefaultCurrent(parser->parser);
- }
-}
-#endif
-
-
-
-/* Event handlers for instance method */
-static void
-myStartElementHandler(void *recv,
- const XML_Char *name, const XML_Char **atts)
-{
- XMLParser* parser;
- VALUE attrhash;
-
- GET_PARSER(recv, parser);
-#ifdef NEW_EXPAT
- parser->lastAttrs = atts;
-#endif
- attrhash = rb_hash_new();
- while (*atts) {
- const char* key = *atts++;
- const char* val = *atts++;
- rb_hash_aset(attrhash,
- FO_(TO_(ENC_(rb_str_new2((char*)key)))),
- TO_(ENC_(rb_str_new2((char*)val))));
- }
- rb_funcall((VALUE)recv, id_startElementHandler, 2,
- TO_(ENC_(rb_str_new2((char*)name))), attrhash);
-}
-
-static void
-myEndElementHandler(void *recv,
- const XML_Char *name)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_endElementHandler, 1,
- TO_(ENC_(rb_str_new2((char*)name))));
-}
-
-static void
-myCharacterDataHandler(void *recv,
- const XML_Char *s,
- int len)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_characterDataHandler, 1,
- TO_(ENC_(rb_str_new((char*)s, len))));
-}
-
-static void
-myProcessingInstructionHandler(void *recv,
- const XML_Char *target,
- const XML_Char *data)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_processingInstructionHandler, 2,
- TO_(ENC_(rb_str_new2((char*)target))),
- TO_(ENC_(rb_str_new2((char*)data))));
-}
-
-static void
-myDefaultHandler(void *recv,
- const XML_Char *s,
- int len)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_defaultHandler, 1,
- TO_(ENC_(rb_str_new((char*)s, len))));
-}
-
-#ifdef NEW_EXPAT
-static void
-myDefaultExpandHandler(void *recv,
- const XML_Char *s,
- int len)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_defaultExpandHandler, 1,
- TO_(ENC_(rb_str_new((char*)s, len))));
-}
-#endif
-
-void
-myUnparsedEntityDeclHandler(void *recv,
- const XML_Char *entityName,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId,
- const XML_Char *notationName)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_unparsedEntityDeclHandler, 5,
- TO_(ENC_(rb_str_new2((char*)entityName))),
- (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- TO_(ENC_(rb_str_new2((char*)systemId))),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil),
- TO_(ENC_(rb_str_new2((char*)notationName))));
-}
-
-void
-myNotationDeclHandler(void *recv,
- const XML_Char *notationName,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_notationDeclHandler, 4,
- TO_(ENC_(rb_str_new2((char*)notationName))),
- (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- (systemId ? TO_(ENC_(rb_str_new2((char*)systemId))) : Qnil),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil));
-}
-
-int
-myExternalEntityRefHandler(XML_Parser xmlparser,
- const XML_Char *context,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId)
-{
- XMLParser* parser;
- VALUE recv;
- VALUE ret;
-
- recv = (VALUE)XML_GetUserData(xmlparser);
- GET_PARSER(recv, parser);
- ret = rb_funcall(recv, id_externalEntityRefHandler, 4,
- (context ? TO_(ENC_(rb_str_new2((char*)context))): Qnil),
- (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- (systemId ? TO_(ENC_(rb_str_new2((char*)systemId))) : Qnil),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil));
- /* The error status in this handler should be returned
- by the exception. */
- return Qnil;
-}
-
-#ifdef NEW_EXPAT
-static void
-myCommentHandler(void *recv,
- const XML_Char *s)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_commentHandler, 1,
- TO_(ENC_(rb_str_new2((char*)s))));
-}
-
-static void
-myStartCdataSectionHandler(void *recv)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_startCdataSectionHandler, 0);
-}
-
-static void
-myEndCdataSectionHandler(void *recv)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_endCdataSectionHandler, 0);
-}
-
-static void
-myStartNamespaceDeclHandler(void *recv,
- const XML_Char *prefix,
- const XML_Char *uri)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_startNamespaceDeclHandler, 2,
- (prefix ? TO_(ENC_(rb_str_new2((char*)prefix))) : Qnil),
- (uri ? TO_(ENC_(rb_str_new2((char*)uri))) : Qnil));
-}
-
-static void
-myEndNamespaceDeclHandler(void *recv,
- const XML_Char *prefix)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_endNamespaceDeclHandler, 1,
- (prefix ? TO_(ENC_(rb_str_new2((char*)prefix))) : Qnil));
-}
-
-static int
-myNotStandaloneHandler(void *recv)
-{
- XMLParser* parser;
- VALUE v;
-
- GET_PARSER(recv, parser);
- v = rb_funcall((VALUE)recv, id_notStandaloneHandler, 0);
- Check_Type(v, T_FIXNUM);
- return FIX2INT(v);
-}
-#endif
-
-#ifdef HAVE_XML_SETPARAMENTITYPARSING
-static void
-#ifdef HAVE_EXPAT_H
-myStartDoctypeDeclHandler(void *recv,
- const XML_Char *doctypeName,
- const XML_Char *sysid,
- const XML_Char *pubid,
- int has_internal_subset)
-#else
-myStartDoctypeDeclHandler(void *recv,
- const XML_Char *doctypeName)
-#endif
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
-#ifdef HAVE_EXPAT_H
- rb_funcall((VALUE)recv, id_startDoctypeDeclHandler, 4,
- TO_(ENC_(rb_str_new2((char*)doctypeName))),
- (sysid ? TO_(ENC_(rb_str_new2((char*)sysid))) : Qnil),
- (pubid ? TO_(ENC_(rb_str_new2((char*)pubid))) : Qnil),
- (has_internal_subset ? Qtrue : Qfalse));
-#else
- rb_funcall((VALUE)recv, id_startDoctypeDeclHandler, 4,
- TO_(ENC_(rb_str_new2((char*)doctypeName))),
- Qnil, Qnil, Qfalse);
-#endif
-}
-
-static void
-myEndDoctypeDeclHandler(void *recv)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_endDoctypeDeclHandler, 0);
-}
-#endif
-
-
-#ifdef HAVE_EXPAT_H
-
-static void
-myElementDeclHandler(void *recv,
- const XML_Char *name,
- XML_Content *model)
-{
- XMLParser* parser;
- VALUE content;
- GET_PARSER(recv, parser);
- content = makeContentArray(parser, model);
- rb_funcall((VALUE)recv, id_elementDeclHandler, 2,
- TO_(ENC_(rb_str_new2(name))), content);
-}
-
-static void
-myAttlistDeclHandler (void *recv,
- const XML_Char *elname,
- const XML_Char *attname,
- const XML_Char *att_type,
- const XML_Char *dflt,
- int isrequired)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_attlistDeclHandler, 5,
- TO_(ENC_(rb_str_new2(elname))),
- TO_(ENC_(rb_str_new2((char*)attname))),
- TO_(ENC_(rb_str_new2((char*)att_type))),
- (dflt ? TO_(ENC_(rb_str_new2((char*)dflt))) : Qnil),
- (isrequired ? Qtrue : Qfalse));
-}
-
-static void
-myXmlDeclHandler (void *recv,
- const XML_Char *version,
- const XML_Char *encoding,
- int standalone)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_xmlDeclHandler, 3,
- (version ? TO_(ENC_(rb_str_new2(version))) : Qnil),
- (encoding ? TO_(ENC_(rb_str_new2((char*)encoding))) : Qnil),
- INT2FIX(standalone));
-}
-
-static void
-myEntityDeclHandler (void *recv,
- const XML_Char *entityName,
- int is_parameter_entity,
- const XML_Char *value,
- int value_length,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId,
- const XML_Char *notationName)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_entityDeclHandler, 7,
- TO_(ENC_(rb_str_new2(entityName))),
- (is_parameter_entity ? Qtrue : Qfalse),
- TO_(ENC_(rb_str_new((char*)value, value_length))),
- (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- (systemId ? TO_(ENC_(rb_str_new2((char*)systemId))) : Qnil),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil),
- (notationName ? TO_(ENC_(rb_str_new2((char*)notationName)))
- : Qnil));
-}
-
-#endif
-
-#if 0
-static void
-myExternalParsedEntityDeclHandler(void *recv,
- const XML_Char *entityName,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_externalParsedEntityDeclHandler, 4,
- TO_(ENC_(rb_str_new2((char*)entityName))),
- (base ? TO_(ENC_(rb_str_new2((char*)base))) : Qnil),
- TO_(ENC_(rb_str_new2((char*)systemId))),
- (publicId ? TO_(ENC_(rb_str_new2((char*)publicId))) : Qnil));
-}
-
-static void
-myInternalParsedEntityDeclHandler(void *recv,
- const XML_Char *entityName,
- const XML_Char *replacementText,
- int replacementTextLength)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_internalParsedEntityDeclHandler, 2,
- TO_(ENC_(rb_str_new2((char*)entityName))),
- TO_(ENC_(rb_str_new((char*)replacementText,
- replacementTextLength))));
-}
-#endif
-
-
-static VALUE
-XMLEncoding_map(VALUE obj, VALUE i)
-{
- return i;
-}
-
-static VALUE
-XMLEncoding_convert(VALUE obj, VALUE str)
-{
- return INT2FIX('?');
-}
-
-static int
-myEncodingConv(void *data, const char *s)
-{
- VALUE v;
- int len;
- int slen = RSTRING_PTR(rb_ivar_get((VALUE)data,
- id_map))[*(unsigned char*)s];
-
- v = rb_funcall((VALUE)data, id_convert, 1, ENC_(rb_str_new((char*)s, -slen)));
- switch (TYPE(v)) {
- case T_FIXNUM:
- return FIX2INT(v);
- case T_STRING:
- len = RSTRING_LEN(v);
- if (len == 1) {
- return (unsigned char)*RSTRING_PTR(v);
- }
- else if (len >= 2) {
- return (unsigned char)*RSTRING_PTR(v) |
- (unsigned char)*(RSTRING_PTR(v) + 1) << 8;
- }
- }
- return 0;
-}
-
-#if 0
-static int
-iterUnknownEncodingHandler(void *recv,
- const XML_Char *name,
- XML_Encoding *info)
-{
- XMLParser* parser;
- VALUE ret;
-
- if (!rb_method_boundp(CLASS_OF((VALUE)recv), id_unknownEncoding, 0))
- return 0;
-
- GET_PARSER(recv, parser);
- ret = rb_yield(rb_ary_new3(4, symUNKNOWN_ENCODING,
- TO_(ENC_(rb_str_new2((char*)name))), Qnil, recv));
- if (TYPE(ret) == T_OBJECT && rb_obj_is_kind_of(ret, cXMLEncoding)) {
- int i;
- ID mid = rb_intern("map");
- VALUE cmap = rb_str_new(NULL, 256);
- rb_ivar_set(ret, id_map, cmap);
-
- for (i = 0; i < 256; i++) {
- VALUE m = rb_funcall(ret, mid, 1, INT2FIX(i));
- RSTRING_PTR(cmap)[i] = info->map[i] = FIX2INT(m);
- }
- /* protect object form GC */
- rb_ivar_set(recv, rb_intern("_encoding"), ret);
- info->data = (void*)ret;
- info->convert = myEncodingConv;
- return 1;
- }
-
- return 0;
-}
-#endif
-
-#ifdef XML_ENC_PATH
-/*
- * Encoding map functions come from XML::Parser Version 2.19
- *
- * Copyright 1998 Larry Wall and Clark Cooper
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the same terms as Perl itself.
- */
-static Encinfo*
-getEncinfo(char* data, int size)
-{
- Encmap_Header* header = (Encmap_Header*)data;
- unsigned short prefixes_size;
- unsigned short bytemap_size;
- Encinfo* ret;
- int i;
- PrefixMap* prefixes;
- unsigned short *bytemap;
-
- if (size < sizeof(Encmap_Header) || ntohl(header->magic) != ENCMAP_MAGIC)
- return NULL;
- prefixes_size = ntohs(header->pfsize);
- bytemap_size = ntohs(header->bmsize);
- if (size != (sizeof(Encmap_Header) +
- prefixes_size * sizeof(PrefixMap) +
- bytemap_size * sizeof(unsigned short)))
- return NULL;
- if ((ret = (Encinfo*)malloc(sizeof(Encinfo))) == NULL) {
- return NULL;
- }
- ret->prefixes_size = prefixes_size;
- ret->bytemap_size = bytemap_size;
- for (i = 0; i < 256; i++)
- ret->firstmap[i] = ntohl(header->map[i]);
- prefixes = (PrefixMap*)(data + sizeof(Encmap_Header));
- bytemap = (unsigned short*)(data + sizeof(Encmap_Header)
- + sizeof(PrefixMap)*prefixes_size);
- if ((ret->prefixes =
- (PrefixMap*)malloc(sizeof(PrefixMap)*prefixes_size)) == NULL) {
- free(ret);
- return NULL;
- }
- if ((ret->bytemap =
- (unsigned short*)malloc(sizeof(unsigned short)*bytemap_size)) == NULL) {
- free(ret->prefixes);
- free(ret);
- return NULL;
- }
- for (i = 0; i < prefixes_size; i++, prefixes++) {
- ret->prefixes[i].min = prefixes->min;
- ret->prefixes[i].len = prefixes->len;
- ret->prefixes[i].bmap_start = ntohs(prefixes->bmap_start);
- memcpy(ret->prefixes[i].ispfx, prefixes->ispfx,
- sizeof(prefixes->ispfx) + sizeof(prefixes->ischar));
- }
- for (i = 0; i < bytemap_size; i++)
- ret->bytemap[i] = ntohs(bytemap[i]);
-
- return ret;
-}
-
-static int
-convertEncoding(Encinfo* enc, const char* seq)
-{
- PrefixMap* curpfx;
- int count;
- int index = 0;
-
- for (count = 0; count < 4; count++) {
- unsigned char byte = (unsigned char)seq[count];
- unsigned char bndx;
- unsigned char bmsk;
- int offset;
-
- curpfx = &enc->prefixes[index];
- offset = ((int)byte) - curpfx->min;
- if (offset < 0)
- break;
- if (offset >= curpfx->len && curpfx->len != 0)
- break;
-
- bndx = byte >> 3;
- bmsk = 1 << (byte & 0x7);
-
- if (curpfx->ispfx[bndx] & bmsk) {
- index = enc->bytemap[curpfx->bmap_start + offset];
- }
- else if (curpfx->ischar[bndx] & bmsk) {
- return enc->bytemap[curpfx->bmap_start + offset];
- }
- else
- break;
- }
-
- return -1;
-}
-
-static void
-releaseEncoding(Encinfo* enc)
-{
- if (enc) {
- if (enc->prefixes)
- free(enc->prefixes);
- if (enc->bytemap)
- free(enc->bytemap);
- free(enc);
- }
-}
-
-static Encinfo*
-findEncoding(const char* encname)
-{
- FILE* fp;
- Encinfo* enc;
- struct stat st;
- int size;
- int len;
- char file[PATH_MAX] = "\0";
- const char* p;
- char* buf;
-#ifdef DOSISH
- const char sepchar = '\\';
-#else
- const char sepchar = '/';
-#endif
- const char* const encext = ".enc";
-
- rb_secure(2);
- /* make map file path */
- if (XML_ENC_PATH != NULL) {
- strncpy(file, XML_ENC_PATH, PATH_MAX - 1);
- file[PATH_MAX - 1] = '\0';
- }
- len = strlen(file);
- if (len > 0 && len < PATH_MAX - 1 && file[len - 1] != sepchar)
- file[len++] = sepchar;
- for (p = encname; *p && len < PATH_MAX - 1; p++, len++) {
- file[len] = tolower(*p);
- }
- file[len] = '\0';
- strncat(file, encext, PATH_MAX - len -1);
-
- if ((fp = fopen(file, "rb")) == NULL) {
- return NULL;
- }
-
- /* get file length */
- fstat(fileno(fp), &st);
- size = st.st_size;
-
- if ((buf = (char*)malloc(size)) == NULL) {
- fclose(fp);
- return NULL;
- }
-
- fread(buf, 1, size, fp);
- fclose(fp);
- enc = getEncinfo(buf, size);
- free(buf);
- return enc;
-}
-
-#endif
-
-static int
-myUnknownEncodingHandler(void *recv,
- const XML_Char *name,
- XML_Encoding *info)
-{
- XMLParser* parser;
- VALUE ret;
-
- GET_PARSER(recv, parser);
- parser->detectedEncoding = name;
-
- if (!rb_method_boundp(CLASS_OF((VALUE)recv), id_unknownEncoding, 0))
-#ifndef XML_ENC_PATH
- return 0;
-#else
- {
- Encinfo* enc;
-
- if ((enc = findEncoding(name)) != NULL) {
- memcpy(info->map, enc->firstmap, sizeof(int)*256);
- info->data = enc;
- info->convert = (int(*)(void*,const char*))convertEncoding;
- info->release = (void(*)(void*))releaseEncoding;
- return 1;
- }
- else
- return 0;
- }
-#endif
-
- ret = rb_funcall((VALUE)recv, id_unknownEncoding, 1,
- TO_(ENC_(rb_str_new2((char*)name))));
- if (TYPE(ret) == T_OBJECT && rb_obj_is_kind_of(ret, cXMLEncoding)) {
- int i;
- ID mid = rb_intern("map");
- VALUE cmap = rb_str_new(NULL, 256);
- rb_ivar_set(ret, id_map, cmap);
-
- if (OBJ_TAINTED(ret))
- taintParser(parser);
- TO_(cmap);
-
- for (i = 0; i < 256; i++) {
- VALUE m = rb_funcall(ret, mid, 1, INT2FIX(i));
- RSTRING_PTR(cmap)[i] = info->map[i] = FIX2INT(m);
- }
- /* protect object form GC */
- rb_ivar_set((VALUE)recv, rb_intern("_encoding"), ret);
- info->data = (void*)ret;
- info->convert = myEncodingConv;
-
- return 1;
- }
-
- return 0;
-}
-
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
-static void
-mySkippedEntityHandler(void *recv,
- const XML_Char *entityName,
- int is_parameter_entity)
-{
- XMLParser* parser;
- GET_PARSER(recv, parser);
- rb_funcall((VALUE)recv, id_skippedEntityHandler, 2,
- TO_(ENC_(rb_str_new2((char*)entityName))),
- INT2FIX(is_parameter_entity));
-}
-#endif
-
-
-/* constructor */
-static VALUE
-XMLParser_new(int argc, VALUE* argv, VALUE klass)
-{
- XMLParser* parser;
- VALUE obj;
- VALUE arg1;
- VALUE arg2;
- VALUE arg3;
- int count;
- char* encoding = NULL;
-#ifdef NEW_EXPAT
- char* nssep = NULL;
-#endif
- char* context = NULL;
- XMLParser* rootparser = NULL;
- VALUE parent = Qnil;
-
- count = rb_scan_args(argc, argv, "03", &arg1, &arg2, &arg3);
- if (count == 1) {
- /* new(encoding) */
- if (TYPE(arg1) != T_NIL) {
- Check_Type(arg1, T_STRING); /* encoding */
- encoding = RSTRING_PTR(arg1);
- }
- }
- else if (count == 2) {
- /* new(encoding, nschar) */
- /* new(parser, context) */
-#ifdef NEW_EXPAT
- if (TYPE(arg1) != T_DATA) {
- if (TYPE(arg1) != T_NIL) {
- Check_Type(arg1, T_STRING); /* encoding */
- encoding = RSTRING_PTR(arg1);
- }
- Check_Type(arg2, T_STRING); /* nschar */
- nssep = RSTRING_PTR(arg2);
- }
- else {
-#endif
- Check_Type(arg1, T_DATA); /* parser */
- GET_PARSER(arg1, rootparser);
- if (!NIL_P(arg2)) {
- Check_Type(arg2, T_STRING); /* context */
- context = RSTRING_PTR(arg2);
- }
- parent = arg1;
-#ifdef NEW_EXPAT
- }
-#endif
- }
- else if (count == 3) {
- /* new(parser, context, encoding) */
- Check_Type(arg1, T_DATA); /* parser */
- GET_PARSER(arg1, rootparser);
- if (!NIL_P(arg2)) {
- Check_Type(arg2, T_STRING); /* context */
- context = RSTRING_PTR(arg2);
- }
- Check_Type(arg3, T_STRING); /* encoding */
- encoding = RSTRING_PTR(arg3);
- parent = arg1;
- }
-
- /* create object */
- obj = Data_Make_Struct(klass, XMLParser,
- XMLParser_mark, XMLParser_free, parser);
- /* create parser */
- if (rootparser == NULL) {
-#ifdef NEW_EXPAT
- if (nssep == NULL)
- parser->parser = XML_ParserCreate(encoding);
- else
- parser->parser = XML_ParserCreateNS(encoding, nssep[0]);
-#else
- parser->parser = XML_ParserCreate(encoding);
-#endif
- parser->tainted = 0;
- parser->context = NULL;
- }
- else {
- parser->parser = XML_ExternalEntityParserCreate(rootparser->parser,
- context, encoding);
- /* clear all inhrited handlers,
- because handlers should be set in "parse" method */
- XML_SetElementHandler(parser->parser, NULL, NULL);
- XML_SetCharacterDataHandler(parser->parser, NULL);
- XML_SetProcessingInstructionHandler(parser->parser, NULL);
- XML_SetDefaultHandler(parser->parser, NULL);
- XML_SetUnparsedEntityDeclHandler(parser->parser, NULL);
- XML_SetNotationDeclHandler(parser->parser, NULL);
- XML_SetExternalEntityRefHandler(parser->parser, NULL);
-#ifdef NEW_EXPAT
- XML_SetCommentHandler(parser->parser, NULL);
- XML_SetCdataSectionHandler(parser->parser, NULL, NULL);
- XML_SetNamespaceDeclHandler(parser->parser, NULL, NULL);
- XML_SetNotStandaloneHandler(parser->parser, NULL);
-#endif
-#ifdef HAVE_XML_SETDOCTYPEDECLHANDLER
- XML_SetDoctypeDeclHandler(parser->parser, NULL, NULL);
-#endif
-#ifdef HAVE_EXPAT_H
- XML_SetElementDeclHandler(parser->parser, NULL);
- XML_SetAttlistDeclHandler(parser->parser, NULL);
- XML_SetXmlDeclHandler(parser->parser, NULL);
- XML_SetEntityDeclHandler(parser->parser, NULL);
-#endif
-#if 0
- XML_SetExternalParsedEntityDeclHandler(parser->parser, NULL);
- XML_SetInternalParsedEntityDeclHandler(parser->parser, NULL);
-#endif
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
- XML_SetSkippedEntityHandler(parser->parser, NULL);
-#endif
- if (rootparser->tainted)
- parser->tainted |= 1;
- parser->context = context;
- }
- if (!parser->parser)
- rb_raise(eXMLParserError, "cannot create parser");
-
- /* setting up internal data */
- XML_SetUserData(parser->parser, (void*)obj);
- parser->iterator = 0;
- parser->defaultCurrent = 0;
-#ifdef NEW_EXPAT
- parser->lastAttrs = NULL;
-#endif
- parser->parent = parent;
- parser->detectedEncoding = NULL;
-
- rb_obj_call_init(obj, argc, argv);
-
- return obj;
-}
-
-static VALUE
-XMLParser_initialize(VALUE obj)
-{
- return Qnil;
-}
-
-#ifdef HAVE_XML_PARSERRESET
-static VALUE
-XMLParser_reset(int argc, VALUE* argv, VALUE obj)
-{
- XMLParser* parser;
- VALUE vencoding = Qnil;
- char* encoding = NULL;
- int count;
-
- count = rb_scan_args(argc, argv, "01", &vencoding);
-
- GET_PARSER(obj, parser);
- if (count > 0 && TYPE(vencoding) != T_NIL) {
- Check_Type(vencoding, T_STRING);
- encoding = RSTRING_PTR(vencoding);
- }
- XML_ParserReset(parser->parser, encoding);
- /* setting up internal data */
- XML_SetUserData(parser->parser, (void*)obj);
- parser->iterator = 0;
- parser->defaultCurrent = 0;
-#ifdef NEW_EXPAT
- parser->lastAttrs = NULL;
-#endif
- parser->tainted = 0;
- parser->detectedEncoding = NULL;
-
- return obj;
-}
-#endif
-
-static void
-setup_evnet_handlers(XMLParser* parser, VALUE obj) {
- XML_StartElementHandler start = NULL;
- XML_EndElementHandler end = NULL;
-#ifdef NEW_EXPAT
- XML_StartCdataSectionHandler startC = NULL;
- XML_EndCdataSectionHandler endC = NULL;
- XML_StartNamespaceDeclHandler startNS = NULL;
- XML_EndNamespaceDeclHandler endNS = NULL;
-#endif
-#ifdef HAVE_XML_SETDOCTYPEDECLHANDLER
- XML_StartDoctypeDeclHandler startDoctype = NULL;
- XML_EndDoctypeDeclHandler endDoctype = NULL;
-#endif
-
- /* Call as iterator */
- if (parser->iterator) {
- XML_SetElementHandler(parser->parser,
- iterStartElementHandler, iterEndElementHandler);
- XML_SetCharacterDataHandler(parser->parser,
- iterCharacterDataHandler);
- XML_SetProcessingInstructionHandler(parser->parser,
- iterProcessingInstructionHandler);
- /* check dummy default handler */
-#ifdef NEW_EXPAT
- if (rb_method_boundp(CLASS_OF(obj), id_defaultExpandHandler, 0))
- XML_SetDefaultHandlerExpand(parser->parser, iterDefaultHandler);
- else
-#endif
- if (rb_method_boundp(CLASS_OF(obj), id_defaultHandler, 0))
- XML_SetDefaultHandler(parser->parser, iterDefaultHandler);
-
- if (rb_method_boundp(CLASS_OF(obj), id_unparsedEntityDeclHandler, 0))
- XML_SetUnparsedEntityDeclHandler(parser->parser,
- iterUnparsedEntityDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_notationDeclHandler, 0))
- XML_SetNotationDeclHandler(parser->parser,
- iterNotationDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_externalEntityRefHandler, 0))
- XML_SetExternalEntityRefHandler(parser->parser,
- iterExternalEntityRefHandler);
-#ifdef NEW_EXPAT
- if (rb_method_boundp(CLASS_OF(obj), id_commentHandler, 0))
- XML_SetCommentHandler(parser->parser, iterCommentHandler);
-
- if (rb_method_boundp(CLASS_OF(obj), id_startCdataSectionHandler, 0))
- startC = iterStartCdataSectionHandler;
- if (rb_method_boundp(CLASS_OF(obj), id_endCdataSectionHandler, 0))
- endC = iterEndCdataSectionHandler;
- if (startC || endC)
- XML_SetCdataSectionHandler(parser->parser, startC, endC);
-
- if (rb_method_boundp(CLASS_OF(obj), id_startNamespaceDeclHandler, 0))
- startNS = iterStartNamespaceDeclHandler;
- if (rb_method_boundp(CLASS_OF(obj), id_endNamespaceDeclHandler, 0))
- endNS = iterEndNamespaceDeclHandler;
- if (startNS || endNS)
- XML_SetNamespaceDeclHandler(parser->parser, startNS, endNS);
- if (rb_method_boundp(CLASS_OF(obj), id_notStandaloneHandler, 0))
- XML_SetNotStandaloneHandler(parser->parser, myNotStandaloneHandler);
-#endif
-#ifdef HAVE_XML_SETDOCTYPEDECLHANDLER
- if (rb_method_boundp(CLASS_OF(obj), id_startDoctypeDeclHandler, 0))
- startDoctype = iterStartDoctypeDeclHandler;
- if (rb_method_boundp(CLASS_OF(obj), id_endDoctypeDeclHandler, 0))
- endDoctype = iterEndDoctypeDeclHandler;
- if (startDoctype || endDoctype)
- XML_SetDoctypeDeclHandler(parser->parser, startDoctype, endDoctype);
-#endif
-#ifdef HAVE_EXPAT_H
- if (rb_method_boundp(CLASS_OF(obj), id_elementDeclHandler, 0))
- XML_SetElementDeclHandler(parser->parser, iterElementDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_attlistDeclHandler, 0))
- XML_SetAttlistDeclHandler(parser->parser, iterAttlistDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_xmlDeclHandler, 0))
- XML_SetXmlDeclHandler(parser->parser, iterXmlDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_entityDeclHandler, 0))
- XML_SetEntityDeclHandler(parser->parser, iterEntityDeclHandler);
-#endif
-#if 0
- if (rb_method_boundp(CLASS_OF(obj), id_externalParsedEntityDeclHandler, 0))
- XML_SetExternalParsedEntityDeclHandler(parser->parser,
- iterExternalParsedEntityDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_internalParsedEntityDeclHandler, 0))
- XML_SetInternalParsedEntityDeclHandler(parser->parser,
- iterInternalParsedEntityDeclHandler);
-#endif
- /* Call non-iterator version of UnknownEncoding handler,
- because the porcedure block often returns the unexpected value. */
- XML_SetUnknownEncodingHandler(parser->parser,
- myUnknownEncodingHandler,
- (void*)obj);
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
- if (rb_method_boundp(CLASS_OF(obj), id_skippedEntityHandler, 0))
- XML_SetSkippedEntityHandler(parser->parser, iterSkippedEntityHandler);
-#endif
- }
- /* Call as not iterator */
- else {
- if (rb_method_boundp(CLASS_OF(obj), id_startElementHandler, 0))
- start = myStartElementHandler;
- if (rb_method_boundp(CLASS_OF(obj), id_endElementHandler, 0))
- end = myEndElementHandler;
- if (start || end)
- XML_SetElementHandler(parser->parser, start, end);
- if (rb_method_boundp(CLASS_OF(obj), id_characterDataHandler, 0))
- XML_SetCharacterDataHandler(parser->parser,
- myCharacterDataHandler);
- if (rb_method_boundp(CLASS_OF(obj),
- id_processingInstructionHandler, 0))
- XML_SetProcessingInstructionHandler(parser->parser,
- myProcessingInstructionHandler);
-#ifdef NEW_EXPAT
- if (rb_method_boundp(CLASS_OF(obj), id_defaultExpandHandler, 0))
- XML_SetDefaultHandlerExpand(parser->parser, myDefaultExpandHandler);
- else
-#endif
- if (rb_method_boundp(CLASS_OF(obj), id_defaultHandler, 0)) {
- XML_SetDefaultHandler(parser->parser, myDefaultHandler);
- }
- if (rb_method_boundp(CLASS_OF(obj), id_unparsedEntityDeclHandler, 0))
- XML_SetUnparsedEntityDeclHandler(parser->parser,
- myUnparsedEntityDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_notationDeclHandler, 0))
- XML_SetNotationDeclHandler(parser->parser,
- myNotationDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_externalEntityRefHandler, 0))
- XML_SetExternalEntityRefHandler(parser->parser,
- myExternalEntityRefHandler);
-#ifdef NEW_EXPAT
- if (rb_method_boundp(CLASS_OF(obj), id_commentHandler, 0))
- XML_SetCommentHandler(parser->parser, myCommentHandler);
-
- if (rb_method_boundp(CLASS_OF(obj), id_startCdataSectionHandler, 0))
- startC = myStartCdataSectionHandler;
- if (rb_method_boundp(CLASS_OF(obj), id_endCdataSectionHandler, 0))
- endC = myEndCdataSectionHandler;
- if (startC || endC)
- XML_SetCdataSectionHandler(parser->parser, startC, endC);
-
- if (rb_method_boundp(CLASS_OF(obj), id_startNamespaceDeclHandler, 0))
- startNS = myStartNamespaceDeclHandler;
- if (rb_method_boundp(CLASS_OF(obj), id_endNamespaceDeclHandler, 0))
- endNS = myEndNamespaceDeclHandler;
- if (startNS || endNS)
- XML_SetNamespaceDeclHandler(parser->parser, startNS, endNS);
- if (rb_method_boundp(CLASS_OF(obj), id_notStandaloneHandler, 0))
- XML_SetNotStandaloneHandler(parser->parser, myNotStandaloneHandler);
-#endif
-#ifdef HAVE_XML_SETDOCTYPEDECLHANDLER
- if (rb_method_boundp(CLASS_OF(obj), id_startDoctypeDeclHandler, 0))
- startDoctype = myStartDoctypeDeclHandler;
- if (rb_method_boundp(CLASS_OF(obj), id_endDoctypeDeclHandler, 0))
- endDoctype = myEndDoctypeDeclHandler;
- if (startDoctype || endDoctype)
- XML_SetDoctypeDeclHandler(parser->parser, startDoctype, endDoctype);
-#endif
-#ifdef HAVE_EXPAT_H
- if (rb_method_boundp(CLASS_OF(obj), id_elementDeclHandler, 0))
- XML_SetElementDeclHandler(parser->parser, myElementDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_attlistDeclHandler, 0))
- XML_SetAttlistDeclHandler(parser->parser, myAttlistDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_xmlDeclHandler, 0))
- XML_SetXmlDeclHandler(parser->parser, myXmlDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_entityDeclHandler, 0))
- XML_SetEntityDeclHandler(parser->parser, myEntityDeclHandler);
-#endif
-#if 0
- if (rb_method_boundp(CLASS_OF(obj), id_externalParsedEntityDeclHandler, 0))
- XML_SetExternalParsedEntityDeclHandler(parser->parser,
- myExternalParsedEntityDeclHandler);
- if (rb_method_boundp(CLASS_OF(obj), id_internalParsedEntityDeclHandler, 0))
- XML_SetInternalParsedEntityDeclHandler(parser->parser,
- myInternalParsedEntityDeclHandler);
-#endif
- XML_SetUnknownEncodingHandler(parser->parser,
- myUnknownEncodingHandler,
- (void*)obj);
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
- if (rb_method_boundp(CLASS_OF(obj), id_skippedEntityHandler, 0))
- XML_SetSkippedEntityHandler(parser->parser, mySkippedEntityHandler);
-#endif
- }
-}
-
-
-/* parse method */
-static VALUE
-XMLParser_parse(int argc, VALUE* argv, VALUE obj)
-{
- XMLParser* parser;
- int ret;
- VALUE str;
- VALUE isFinal;
- int final = 1;
- int count;
- int fromStream = 0;
- ID mid = rb_intern("gets");
- ID linebuf = rb_intern("_linebuf");
-
- count = rb_scan_args(argc, argv, "02", &str, &isFinal);
- /* If "str" has public "gets" method, it will be considered *stream* */
- if (!rb_obj_is_kind_of(str, rb_cString) &&
- rb_method_boundp(CLASS_OF(str), mid, 1)) {
- fromStream = 1;
- }
- else if (!NIL_P(str)) {
- Check_Type(str, T_STRING);
- }
- if (count >= 2) {
- if (isFinal == Qtrue)
- final = 1;
- else if (isFinal == Qfalse)
- final = 0;
- else
- rb_raise(rb_eTypeError, "not valid value");
- }
-
- GET_PARSER(obj, parser);
-
- parser->iterator = rb_block_given_p();
-
- /* Setup event handlers */
- setup_evnet_handlers(parser, obj);
-
- /* Parse from stream (probably slightly slow) */
- if (fromStream) {
- VALUE buf;
-
- if (OBJ_TAINTED(str))
- taintParser(parser);
- do {
- buf = rb_funcall(str, mid, 0);
- if (!NIL_P(buf)) {
- Check_Type(buf, T_STRING);
- if (OBJ_TAINTED(buf))
- taintParser(parser);
- rb_ivar_set(obj, linebuf, buf); /* protect buf from GC (reasonable?)*/
- ret = XML_Parse(parser->parser,
- RSTRING_PTR(buf), RSTRING_LEN(buf), 0);
- }
- else {
- ret = XML_Parse(parser->parser, NULL, 0, 1);
- }
- if (!ret) {
- int err = XML_GetErrorCode(parser->parser);
- const char* errStr = XML_ErrorString(err);
- rb_raise(eXMLParserError, (char*)errStr);
- }
- } while (!NIL_P(buf));
- return Qnil;
- }
-
- /* Parse string */
- if (!NIL_P(str)) {
-#if defined(HAVE_RUBY_ENCODING_H) && defined(HAVE_XML_PARSERRESET)
- int err;
-#endif
- if (OBJ_TAINTED(str))
- taintParser(parser);
- ret = XML_Parse(parser->parser,
- RSTRING_PTR(str), RSTRING_LEN(str), final);
-#if defined(HAVE_RUBY_ENCODING_H) && defined(HAVE_XML_PARSERRESET)
- /* Ruby 1.9.1 Encoding conversion */
- err = XML_GetErrorCode(parser->parser);
- if (final && err == XML_ERROR_UNKNOWN_ENCODING) {
- rb_encoding* enc;
- volatile VALUE encobj;
- volatile VALUE ustr;
- enc = rb_enc_find(parser->detectedEncoding);
- if ((int)ENC_TO_ENCINDEX(enc) != rb_ascii8bit_encindex()) {
- rb_enc_associate(str, enc);
- encobj = rb_enc_from_encoding(enc_xml);
- /* rb_str_encode may raises an exception */
- ustr = rb_str_encode(str, encobj, 0, Qnil);
- if (!NIL_P(ustr)) {
- XML_ParserReset(parser->parser, "utf-8");
- XML_SetUserData(parser->parser, (void*)obj);
- parser->defaultCurrent = 0;
-#ifdef NEW_EXPAT
- parser->lastAttrs = NULL;
-#endif
- parser->detectedEncoding = NULL;
- setup_evnet_handlers(parser, obj);
- ret = XML_Parse(parser->parser,
- RSTRING_PTR(ustr), RSTRING_LEN(ustr), final);
- }
- }
- }
-#endif
- }
- else
- ret = XML_Parse(parser->parser, NULL, 0, final);
- if (!ret) {
- int err = XML_GetErrorCode(parser->parser);
- const char* errStr = XML_ErrorString(err);
- rb_raise(eXMLParserError, (char*)errStr);
- }
-
- return Qnil;
-}
-
-/* done method */
-static VALUE
-XMLParser_done(VALUE obj)
-{
- XMLParser* parser;
-
- GET_PARSER(obj, parser);
- if (parser->parser) {
- XML_ParserFree(parser->parser);
- parser->parser = NULL;
- }
- return Qnil;
-}
-
-/* defaultCurrent method */
-static VALUE
-XMLParser_defaultCurrent(VALUE obj)
-{
- XMLParser* parser;
-
- GET_PARSER(obj, parser);
- if (!(parser->iterator)) {
- XML_DefaultCurrent(parser->parser);
- }
- else {
- parser->defaultCurrent = 1;
- }
- return Qnil;
-}
-
-/* line method */
-static VALUE
-XMLParser_getCurrentLineNumber(VALUE obj)
-{
- XMLParser* parser;
- int line;
-
- GET_PARSER(obj, parser);
- line = XML_GetCurrentLineNumber(parser->parser);
-
- return INT2FIX(line);
-}
-
-/* column method */
-static VALUE
-XMLParser_getCurrentColumnNumber(VALUE obj)
-{
- XMLParser* parser;
- int column;
-
- GET_PARSER(obj, parser);
- column = XML_GetCurrentColumnNumber(parser->parser);
-
- return INT2FIX(column);
-}
-
-/* byte index method */
-static VALUE
-XMLParser_getCurrentByteIndex(VALUE obj)
-{
- XMLParser* parser;
- long pos;
-
- GET_PARSER(obj, parser);
- pos = XML_GetCurrentByteIndex(parser->parser);
-
- return INT2FIX(pos);
-}
-
-/* set URI base */
-static VALUE
-XMLParser_setBase(VALUE obj, VALUE base)
-{
- XMLParser* parser;
- int ret;
-
- Check_Type(base, T_STRING);
- GET_PARSER(obj, parser);
- if (OBJ_TAINTED(base))
- taintParser(parser);
- ret = XML_SetBase(parser->parser, RSTRING_PTR(base));
-
- return INT2FIX(ret);
-}
-
-/* get URI base */
-static VALUE
-XMLParser_getBase(VALUE obj)
-{
- XMLParser* parser;
- const XML_Char* ret;
-
- GET_PARSER(obj, parser);
- ret = XML_GetBase(parser->parser);
- if (!ret)
- return Qnil;
-
- return TO_(ENC_(rb_str_new2((char*)ret)));
-}
-
-#ifdef NEW_EXPAT
-#if 0
-static VALUE
-XMLParser_getSpecifiedAttributes(VALUE obj)
-{
- XMLParser* parser;
- int count;
- const XML_Char** atts;
- VALUE attrhash;
-
- GET_PARSER(obj, parser);
- atts = parser->lastAttrs;
- if (!atts)
- return Qnil;
- count = XML_GetSpecifiedAttributeCount(parser->parser)/2;
- attrhash = rb_hash_new();
- while (*atts) {
- const char* key = *atts++;
- atts++;
- rb_hash_aset(attrhash, FO_(TO_(ENC_(rb_str_new2((char*)key)))),
- (count-- > 0) ? Qtrue: Qfalse);
- }
-
- return attrhash;
-}
-#else
-static VALUE
-XMLParser_getSpecifiedAttributes(VALUE obj)
-{
- XMLParser* parser;
- int i, count;
- const XML_Char** atts;
- VALUE attrarray;
-
- GET_PARSER(obj, parser);
- atts = parser->lastAttrs;
- if (!atts)
- return Qnil;
- count = XML_GetSpecifiedAttributeCount(parser->parser)/2;
- attrarray = rb_ary_new2(count);
- for (i = 0; i < count; i++, atts+=2) {
- const char* key = *atts;
- rb_ary_push(attrarray, TO_(ENC_(rb_str_new2((char*)key))));
- }
-
- return attrarray;
-}
-#endif
-
-static VALUE
-XMLParser_getCurrentByteCount(VALUE obj)
-{
- XMLParser* parser;
-
- GET_PARSER(obj, parser);
- return INT2FIX(XML_GetCurrentByteCount(parser->parser));
-}
-#endif
-
-#ifdef XML_DTD
-static VALUE
-XMLParser_setParamEntityParsing(VALUE obj, VALUE parsing)
-{
- XMLParser* parser;
- int ret;
-
- Check_Type(parsing, T_FIXNUM);
- GET_PARSER(obj, parser);
- ret = XML_SetParamEntityParsing(parser->parser, FIX2INT(parsing));
-
- return INT2FIX(ret);
-}
-#endif
-
-static VALUE
-XMLParser_s_expatVersion(VALUE obj)
-{
-#if defined(HAVE_EXPAT_H)
- return ENC_(rb_str_new2(XML_ExpatVersion()));
-#elif defined(EXPAT_1_2)
- return ENC_(rb_str_new2("1.2"));
-#elif defined(NEW_EXPAT)
- return ENC_(rb_str_new2("1.1"));
-#else
- return ENC_(rb_str_new2("1.0"));
-#endif
-}
-
-#ifdef HAVE_EXPAT_H
-static VALUE
-XMLParser_setReturnNSTriplet(VALUE obj, VALUE do_nst)
-{
- XMLParser* parser;
- int nst;
-
- GET_PARSER(obj, parser);
- switch (TYPE(do_nst)) {
- case T_TRUE:
- nst = 1;
- break;
- case T_FALSE:
- nst = 0;
- break;
- case T_FIXNUM:
- nst = FIX2INT(do_nst);
- break;
- default:
- rb_raise(rb_eTypeError, "not valid value");
- }
- XML_SetReturnNSTriplet(parser->parser, nst);
-
- return Qnil;
-}
-
-
-static VALUE
-XMLParser_getInputContext(VALUE obj)
-{
- XMLParser* parser;
- const char* buffer;
- int offset;
- int size;
- VALUE ret = Qnil;
-
- GET_PARSER(obj, parser);
- buffer = XML_GetInputContext(parser->parser,
- &offset,
- &size);
- if (buffer && size > 0) {
- ret = rb_ary_new3(2,
- TO_(ENC_(rb_str_new(buffer, size))),
- INT2FIX(offset));
- }
-
- return ret;
-}
-
-
-static VALUE
-XMLParser_getIdAttrribute(VALUE obj)
-{
- XMLParser* parser;
- int idattr;
- const XML_Char** atts;
-
- GET_PARSER(obj, parser);
- atts = parser->lastAttrs;
- if (!atts)
- return Qnil;
- idattr = XML_GetIdAttributeIndex(parser->parser);
- if (idattr < 0)
- return Qnil;
- return TO_(ENC_(rb_str_new2((char*)atts[idattr])));
-}
-#endif
-
-#ifdef HAVE_XML_USEFOREIGNDTD
-static VALUE
-XMLParser_useForeignDTD(VALUE obj, VALUE useDTD)
-{
- XMLParser* parser;
- int dtd;
- int ret;
-
- GET_PARSER(obj, parser);
- switch (TYPE(useDTD)) {
- case T_TRUE:
- dtd = 1;
- break;
- case T_FALSE:
- dtd = 0;
- break;
- case T_FIXNUM:
- dtd = FIX2INT(useDTD);
- break;
- default:
- rb_raise(rb_eTypeError, "not valid value");
- }
- ret = XML_UseForeignDTD(parser->parser, dtd);
-
- return INT2FIX(ret);
-}
-#endif
-
-#ifdef HAVE_XML_GETFEATURELIST
-static VALUE
-XMLParser_s_getFeatureList(VALUE obj)
-{
- const XML_Feature* list;
- VALUE ret = rb_hash_new();
-
- list = XML_GetFeatureList();
- while (list && list->feature) {
- rb_hash_aset(ret, FO_(ENC_(rb_str_new2(list->name))), INT2NUM(list->value));
- list++;
- }
-
- return ret;
-}
-#endif
-
-void
-Init_xmlparser()
-{
- VALUE mXML;
-
-#ifdef HAVE_RUBY_ENCODING_H
- enc_xml = rb_utf8_encoding();
-#endif
-
- eXMLParserError = rb_define_class("XMLParserError", rb_eStandardError);
- cXMLParser = rb_define_class("XMLParser", rb_cObject);
- cXMLEncoding = rb_define_class("XMLEncoding", rb_cObject);
-
- /* Class name aliases */
- if (rb_const_defined(rb_cObject, rb_intern("XML")) == Qtrue)
- mXML = rb_const_get(rb_cObject, rb_intern("XML"));
- else
- mXML = rb_define_module("XML");
- rb_define_const(mXML, "ParserError", eXMLParserError);
- rb_define_const(cXMLParser, "Error", eXMLParserError);
- rb_define_const(mXML, "Parser", cXMLParser);
- rb_define_const(mXML, "Encoding", cXMLEncoding);
-
- rb_define_singleton_method(cXMLParser, "new", XMLParser_new, -1);
- rb_define_singleton_method(cXMLParser, "expatVersion",
- XMLParser_s_expatVersion, 0);
- rb_define_method(cXMLParser, "initialize", XMLParser_initialize, -1);
- rb_define_method(cXMLParser, "parse", XMLParser_parse, -1);
- rb_define_method(cXMLParser, "done", XMLParser_done, 0);
- rb_define_method(cXMLParser, "defaultCurrent", XMLParser_defaultCurrent, 0);
- rb_define_method(cXMLParser, "line", XMLParser_getCurrentLineNumber, 0);
- rb_define_method(cXMLParser, "column", XMLParser_getCurrentColumnNumber, 0);
- rb_define_method(cXMLParser, "byteIndex", XMLParser_getCurrentByteIndex, 0);
- rb_define_method(cXMLParser, "setBase", XMLParser_setBase, 1);
- rb_define_method(cXMLParser, "getBase", XMLParser_getBase, 0);
-#ifdef NEW_EXPAT
- rb_define_method(cXMLParser, "getSpecifiedAttributes",
- XMLParser_getSpecifiedAttributes, 0);
- rb_define_method(cXMLParser, "byteCount", XMLParser_getCurrentByteCount, 0);
-#endif
-#ifdef XML_DTD
- rb_define_method(cXMLParser, "setParamEntityParsing",
- XMLParser_setParamEntityParsing, 1);
-#endif
-#ifdef HAVE_EXPAT_H
- rb_define_method(cXMLParser, "setReturnNSTriplet",
- XMLParser_setReturnNSTriplet, 1);
- rb_define_method(cXMLParser, "getInputContext",
- XMLParser_getInputContext, 0);
- rb_define_method(cXMLParser, "getIdAttribute",
- XMLParser_getIdAttrribute, 0);
-#endif
-
-#ifdef HAVE_XML_PARSERRESET
- rb_define_method(cXMLParser, "reset", XMLParser_reset, -1);
-#endif
-
- rb_define_method(cXMLEncoding, "map", XMLEncoding_map, 1);
- rb_define_method(cXMLEncoding, "convert", XMLEncoding_convert, 1);
-
-#ifdef HAVE_XML_USEFOREIGNDTD
- rb_define_method(cXMLParser, "useForeignDTD",
- XMLParser_useForeignDTD, 1);
-#endif
-#ifdef HAVE_XML_GETFEATURELIST
- rb_define_singleton_method(cXMLParser, "getFeatureList",
- XMLParser_s_getFeatureList, 0);
-#endif
-
-#define DEFINE_EVENT_CODE(klass, name) \
- rb_define_const(klass, #name, sym##name = ID2SYM(rb_intern(#name)))
-
- DEFINE_EVENT_CODE(cXMLParser, START_ELEM);
- DEFINE_EVENT_CODE(cXMLParser, END_ELEM);
- DEFINE_EVENT_CODE(cXMLParser, CDATA);
- DEFINE_EVENT_CODE(cXMLParser, PI);
- DEFINE_EVENT_CODE(cXMLParser, DEFAULT);
- DEFINE_EVENT_CODE(cXMLParser, UNPARSED_ENTITY_DECL);
- DEFINE_EVENT_CODE(cXMLParser, NOTATION_DECL);
- DEFINE_EVENT_CODE(cXMLParser, EXTERNAL_ENTITY_REF);
-#ifdef NEW_EXPAT
- DEFINE_EVENT_CODE(cXMLParser, COMMENT);
- DEFINE_EVENT_CODE(cXMLParser, START_CDATA);
- DEFINE_EVENT_CODE(cXMLParser, END_CDATA);
- DEFINE_EVENT_CODE(cXMLParser, START_NAMESPACE_DECL);
- DEFINE_EVENT_CODE(cXMLParser, END_NAMESPACE_DECL);
-#endif
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
- DEFINE_EVENT_CODE(cXMLParser, SKIPPED_ENTITY);
-#endif
-#ifdef XML_DTD
- rb_define_const(cXMLParser, "PARAM_ENTITY_PARSING_NEVER",
- XML_PARAM_ENTITY_PARSING_NEVER);
- rb_define_const(cXMLParser, "PARAM_ENTITY_PARSING_UNLESS_STANDALONE",
- XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE);
- rb_define_const(cXMLParser, "PARAM_ENTITY_PARSING_ALWAYS",
- XML_PARAM_ENTITY_PARSING_ALWAYS);
-#endif
-#ifdef HAVE_XML_SETDOCTYPEDECLHANDLER
- DEFINE_EVENT_CODE(cXMLParser, START_DOCTYPE_DECL);
- DEFINE_EVENT_CODE(cXMLParser, END_DOCTYPE_DECL);
-#endif
-#ifdef HAVE_EXPAT_H
- DEFINE_EVENT_CODE(cXMLParser, ELEMENT_DECL);
- DEFINE_EVENT_CODE(cXMLParser, ATTLIST_DECL);
- DEFINE_EVENT_CODE(cXMLParser, XML_DECL);
- DEFINE_EVENT_CODE(cXMLParser, ENTITY_DECL);
-#endif
-#if 0
- DEFINE_EVENT_CODE(cXMLParser, EXTERNAL_PARSED_ENTITY_DECL);
- DEFINE_EVENT_CODE(cXMLParser, INTERNAL_PARSED_ENTITY_DECL);
-#endif
-#if 0
- DEFINE_EVENT_CODE(cXMLParser, UNKNOWN_ENCODING);
-#endif
-
- id_map = rb_intern("_map");
- id_startElementHandler = rb_intern("startElement");
- id_endElementHandler = rb_intern("endElement");
- id_characterDataHandler = rb_intern("character");
- id_processingInstructionHandler = rb_intern("processingInstruction");
- id_defaultHandler = rb_intern("default");
- id_unparsedEntityDeclHandler = rb_intern("unparsedEntityDecl");
- id_notationDeclHandler = rb_intern("notationDecl");
- id_externalEntityRefHandler = rb_intern("externalEntityRef");
-#ifdef NEW_EXPAT
- id_defaultExpandHandler = rb_intern("defaultExpand");
- id_commentHandler = rb_intern("comment");
- id_startCdataSectionHandler = rb_intern("startCdata");
- id_endCdataSectionHandler = rb_intern("endCdata");
- id_startNamespaceDeclHandler = rb_intern("startNamespaceDecl");
- id_endNamespaceDeclHandler = rb_intern("endNamespaceDecl");
- id_notStandaloneHandler = rb_intern("notStandalone");
-#endif
-#ifdef HAVE_XML_SETDOCTYPEDECLHANDLER
- id_startDoctypeDeclHandler = rb_intern("startDoctypeDecl");
- id_endDoctypeDeclHandler = rb_intern("endDoctypeDecl");
-#endif
- id_unknownEncoding = rb_intern("unknownEncoding");
- id_convert = rb_intern("convert");
-#ifdef HAVE_EXPAT_H
- id_elementDeclHandler = rb_intern("elementDecl");
- id_attlistDeclHandler = rb_intern("attlistDecl");
- id_xmlDeclHandler = rb_intern("xmlDecl");
- id_entityDeclHandler = rb_intern("entityDecl");
-#endif
-#if 0
- id_externalParsedEntityDeclHandler = rb_intern("externalParsedEntityDecl");
- id_internalParsedEntityDeclHandler = rb_intern("internalParsedEntityDecl");
-#endif
-#ifdef HAVE_XML_SETSKIPPEDENTITYHANDLER
- id_skippedEntityHandler = rb_intern("skippedEntity");
-#endif
-}
diff --git a/lib/xml/dom/core.rb b/lib/xml/dom/core.rb
index 6a157ee..ab260e7 100644
--- a/lib/xml/dom/core.rb
+++ b/lib/xml/dom/core.rb
@@ -1846,8 +1846,6 @@ return the string representation of the Attr.
value << """
when ?<
value << "<"
- when ?>
- value << ">"
else
value << code
end
diff --git a/lib/xml/dom2/attr.rb b/lib/xml/dom2/attr.rb
index 775ffa1..53bb911 100644
--- a/lib/xml/dom2/attr.rb
+++ b/lib/xml/dom2/attr.rb
@@ -122,9 +122,7 @@ return the string representation of the Attr.
value << """
elsif c == "<"
value << "<"
- elsif c == ">"
- value << ">"
- else
+ else
value << c
end
end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-xmlparser.git
More information about the Pkg-ruby-extras-commits
mailing list