mame-xmlparser 0.6.81.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. data/Encodings/README.ja +18 -0
  2. data/Encodings/euc-jp.enc +0 -0
  3. data/Encodings/shift_jis.enc +0 -0
  4. data/History.txt +5 -0
  5. data/Manifest.txt +118 -0
  6. data/README +697 -0
  7. data/README.ja +789 -0
  8. data/README.txt +49 -0
  9. data/Rakefile +30 -0
  10. data/ext/encoding.h +91 -0
  11. data/ext/extconf.rb +58 -0
  12. data/ext/xmlparser.c +2231 -0
  13. data/lib/sax.rb +1 -0
  14. data/lib/saxdriver.rb +1 -0
  15. data/lib/wget.rb +47 -0
  16. data/lib/xml/dom/builder-ja.rb +58 -0
  17. data/lib/xml/dom/builder.rb +310 -0
  18. data/lib/xml/dom/core.rb +3276 -0
  19. data/lib/xml/dom/digest.rb +94 -0
  20. data/lib/xml/dom/visitor.rb +182 -0
  21. data/lib/xml/dom2/attr.rb +213 -0
  22. data/lib/xml/dom2/cdatasection.rb +76 -0
  23. data/lib/xml/dom2/characterdata.rb +177 -0
  24. data/lib/xml/dom2/comment.rb +81 -0
  25. data/lib/xml/dom2/core.rb +19 -0
  26. data/lib/xml/dom2/document.rb +317 -0
  27. data/lib/xml/dom2/documentfragment.rb +82 -0
  28. data/lib/xml/dom2/documenttype.rb +102 -0
  29. data/lib/xml/dom2/dombuilder.rb +277 -0
  30. data/lib/xml/dom2/dombuilderfilter.rb +12 -0
  31. data/lib/xml/dom2/domentityresolver.rb +13 -0
  32. data/lib/xml/dom2/domentityresolverimpl.rb +37 -0
  33. data/lib/xml/dom2/domexception.rb +95 -0
  34. data/lib/xml/dom2/domimplementation.rb +61 -0
  35. data/lib/xml/dom2/dominputsource.rb +29 -0
  36. data/lib/xml/dom2/element.rb +533 -0
  37. data/lib/xml/dom2/entity.rb +110 -0
  38. data/lib/xml/dom2/entityreference.rb +107 -0
  39. data/lib/xml/dom2/namednodemap.rb +138 -0
  40. data/lib/xml/dom2/node.rb +587 -0
  41. data/lib/xml/dom2/nodelist.rb +231 -0
  42. data/lib/xml/dom2/notation.rb +86 -0
  43. data/lib/xml/dom2/processinginstruction.rb +155 -0
  44. data/lib/xml/dom2/text.rb +128 -0
  45. data/lib/xml/dom2/xpath.rb +398 -0
  46. data/lib/xml/encoding-ja.rb +42 -0
  47. data/lib/xml/parser.rb +13 -0
  48. data/lib/xml/parserns.rb +236 -0
  49. data/lib/xml/sax.rb +353 -0
  50. data/lib/xml/saxdriver.rb +370 -0
  51. data/lib/xml/xpath.rb +3284 -0
  52. data/lib/xml/xpath.ry +2352 -0
  53. data/lib/xmldigest.rb +1 -0
  54. data/lib/xmlencoding-ja.rb +11 -0
  55. data/lib/xmltree.rb +1 -0
  56. data/lib/xmltreebuilder-ja.rb +9 -0
  57. data/lib/xmltreebuilder.rb +1 -0
  58. data/lib/xmltreevisitor.rb +1 -0
  59. data/samples/buildertest.rb +47 -0
  60. data/samples/buildertest2.rb +50 -0
  61. data/samples/digesttest.rb +26 -0
  62. data/samples/digesttest2.rb +192 -0
  63. data/samples/doctype.rb +40 -0
  64. data/samples/doctype.xml +21 -0
  65. data/samples/doctypei.rb +19 -0
  66. data/samples/document.dtd +77 -0
  67. data/samples/dom2/dom2test1.rb +7 -0
  68. data/samples/dom2/dom2test2.rb +10 -0
  69. data/samples/dom2/gtkxpath.rb +259 -0
  70. data/samples/dom2/test1.xml +16 -0
  71. data/samples/dom2/test2.xml +7 -0
  72. data/samples/dtd/ext1.dtd +4 -0
  73. data/samples/dtd/ext2.dtd +1 -0
  74. data/samples/dtd/extdtd.rb +34 -0
  75. data/samples/dtd/extdtd.xml +5 -0
  76. data/samples/expat-1.2/CVS/Entries +8 -0
  77. data/samples/expat-1.2/CVS/Repository +1 -0
  78. data/samples/expat-1.2/CVS/Root +1 -0
  79. data/samples/expat-1.2/ext.ent +2 -0
  80. data/samples/expat-1.2/exttest.rb +82 -0
  81. data/samples/expat-1.2/exttesti.rb +81 -0
  82. data/samples/expat-1.2/hoge.dtd +7 -0
  83. data/samples/expat-1.2/idattr.xml +8 -0
  84. data/samples/expat-1.2/idtest.rb +21 -0
  85. data/samples/expat-1.2/idtest.xml +12 -0
  86. data/samples/expat-1.2/xmlextparser.rb +39 -0
  87. data/samples/gtktree.rb +146 -0
  88. data/samples/idattrtest.rb +28 -0
  89. data/samples/index_euc.xml +72 -0
  90. data/samples/index_jis.xml +72 -0
  91. data/samples/index_noenc.xml +71 -0
  92. data/samples/index_sjis.xml +72 -0
  93. data/samples/index_u16.xml +0 -0
  94. data/samples/index_u8.xml +72 -0
  95. data/samples/my-html.rb +65 -0
  96. data/samples/namespaces/CVS/Entries +5 -0
  97. data/samples/namespaces/CVS/Repository +1 -0
  98. data/samples/namespaces/CVS/Root +1 -0
  99. data/samples/namespaces/namespace1.rb +29 -0
  100. data/samples/namespaces/namespace1.xml +10 -0
  101. data/samples/namespaces/namespace2.rb +41 -0
  102. data/samples/namespaces/namespace2.xml +12 -0
  103. data/samples/nstest.rb +21 -0
  104. data/samples/saxtest.rb +70 -0
  105. data/samples/test/featurelist.rb +11 -0
  106. data/samples/test/skippedentity.rb +48 -0
  107. data/samples/test/useforeigndtd.rb +42 -0
  108. data/samples/treetest.rb +14 -0
  109. data/samples/visitor.rb +29 -0
  110. data/samples/visitortest.rb +36 -0
  111. data/samples/writer.rb +43 -0
  112. data/samples/xmlcheck.rb +40 -0
  113. data/samples/xmlcomments.rb +30 -0
  114. data/samples/xmlevent.rb +76 -0
  115. data/samples/xmliter.rb +57 -0
  116. data/samples/xmlstats.rb +167 -0
  117. data/samples/xpointer.rb +233 -0
  118. data/samples/xpointertest.rb +23 -0
  119. metadata +185 -0
@@ -0,0 +1,7 @@
1
+ #! /usr/local/bin/ruby
2
+
3
+ require 'xml/dom2/dombuilder'
4
+
5
+ b = XML::DOM::DOMBuilder.new
6
+ doc = b.parse($<.read)
7
+ print doc.to_s, "\n"
@@ -0,0 +1,10 @@
1
+ #! /usr/local/bin/ruby
2
+
3
+ require 'xml/dom2/core'
4
+
5
+ builder = XML::DOM::DOMImplementation.instance.createDOMBuilder
6
+ #builder.createCDATASection = true
7
+ doc = builder.parseURI(ARGV[0])
8
+ doc.each do |a|
9
+ p [a.nodeName, a._getNamespaces(nil)] if a.nodeType == XML::DOM::Node::ELEMENT_NODE
10
+ end
@@ -0,0 +1,259 @@
1
+ #! /usr/local/bin/ruby
2
+
3
+ ## XPath demo for Gtk
4
+ ## 1999 by yoshidam
5
+ ##
6
+
7
+ require 'gtk'
8
+ require 'xml/dom2/core'
9
+ require 'xml/dom2/dombuilder'
10
+ require 'xml/dom2/xpath'
11
+ #require 'uconv'
12
+
13
+ GC.disable
14
+
15
+ ## TREE_MODE = 0: expand entity references, and not create DOCUMENT_TYPE_NODE
16
+ ## TREE_MODE = 1: not expand entity references
17
+ TREE_MODE = 0
18
+ ## enpand tree at the beginning
19
+ EXPAND_TREE = false
20
+ ## trim extra white spaces
21
+ TRIM = true
22
+ ## concatenate folding lines
23
+ UNFOLD = false
24
+ ## parse external entity
25
+ PARSE_EXT = true
26
+
27
+ ## Gtk resources
28
+ #Gtk::RC::parse_string <<EOS
29
+ #style "default" {
30
+ # fontset = "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*,\
31
+ # -*-fixed-medium-r-normal--14-*-*-*-*-*-jisx0208.1983-0,*"
32
+ #}
33
+ #widget_class "*" style "default"
34
+ #EOS
35
+
36
+ def unfold(str)
37
+ str.
38
+ gsub(/([��-��])\n\s*([��-��])/, '\1\2').
39
+ gsub(/([a-z])-\n\s+([a-z])/, '\1\2').
40
+ gsub(/\s+/, ' ')
41
+ end
42
+
43
+ module Gtk
44
+ class TreeItem
45
+ attr :xml_node
46
+ alias initialize0 initialize
47
+ def initialize(*arg)
48
+ initialize0(arg[0])
49
+ @xml_node = arg[1]
50
+ end
51
+ end
52
+ end
53
+
54
+ ## Extend the Node class to manipulate the Gtk::Tree
55
+ module XML
56
+ module DOM
57
+ class Node
58
+ ## a node to Gtk::Tree
59
+ def appendNodeToTree(node)
60
+ if @treeitem.nil?
61
+ raise "Cannot append tree"
62
+ end
63
+ if @tree.nil?
64
+ @tree = Gtk::Tree::new()
65
+ @treeitem.set_subtree(@tree)
66
+ if EXPAND_TREE
67
+ @tree.show
68
+ @treeitem.expand
69
+ end
70
+ end
71
+ @tree.append(node)
72
+ end
73
+
74
+ ## create Gtk::Tree from XML::Node tree
75
+ def newTreeItem(parent = nil)
76
+ if !@treeitem.nil?
77
+ raise "tree item already exist"
78
+ end
79
+
80
+ case self.nodeType
81
+ when TEXT_NODE
82
+ attr = self.parentNode.attributes
83
+ if attr && attr['xml:space'] != 'preserve'
84
+ self.nodeValue = unfold(self.nodeValue) if UNFOLD
85
+ end
86
+ # str = "\"" + Uconv::u8toeuc(self.nodeValue) + "\""
87
+ str = "\"" + self.nodeValue + "\""
88
+ when CDATA_SECTION_NODE
89
+ # str = "<![CDATA[" + Uconv::u8toeuc(self.nodeValue) + "]]>"
90
+ str = "<![CDATA[" + self.nodeValue + "]]>"
91
+ when PROCESSING_INSTRUCTION_NODE
92
+ # str = "?" + Uconv::u8toeuc(self.nodeValue)
93
+ str = "?" + self.nodeValue
94
+ when ELEMENT_NODE
95
+ attr = ''
96
+ @attr.each do |a| ## self.attributes do |a|
97
+ attr += a.to_s + ", "
98
+ end if @attr
99
+ attr.chop!
100
+ attr.chop!
101
+ # str = Uconv::u8toeuc(nodeName)
102
+ str = nodeName
103
+ if (attr != '');
104
+ # str += " (" + Uconv::u8toeuc(attr) + ")"
105
+ str += " (" + attr + ")"
106
+ end
107
+ when COMMENT_NODE
108
+ # str = "<!--" + Uconv::u8toeuc(self.nodeValue) + "-->"
109
+ str = "<!--" + self.nodeValue + "-->"
110
+ when DOCUMENT_TYPE_NODE
111
+ # str = "#doctype: " + Uconv::u8toeuc(self.nodeName)
112
+ str = "#doctype: " + self.nodeName
113
+ when ENTITY_REFERENCE_NODE
114
+ # str = "&" + Uconv::u8toeuc(self.nodeName) + ";"
115
+ str = "&" + self.nodeName + ";"
116
+ else
117
+ # str = Uconv::u8toeuc(self.nodeName)
118
+ str = self.nodeName
119
+ end
120
+ str.gsub!(/\n/, "\\\\n")
121
+ @treeitem = Gtk::TreeItem::new(str, self)
122
+ @selecting = false
123
+ @treeitem.signal_connect("select") do |w|
124
+ # $text.set_text(Uconv::u8toeuc(w.xml_node.makeXPath)) unless @selecting
125
+ $text.set_text(w.xml_node.makeXPath) unless @selecting
126
+ end
127
+ if (parent.nil? && !self.parentNode.nil?)
128
+ self.parentNode.appendNodeToTree(@treeitem)
129
+ else
130
+ parent.append(@treeitem)
131
+ end
132
+ @treeitem.show
133
+ self.childNodes do |c|
134
+ c.newTreeItem
135
+ end
136
+ end
137
+
138
+ def selectNode
139
+ @selecting = true
140
+ parentNode.showTree if parentNode
141
+ if @treeitem
142
+ @treeitem.activate
143
+ else
144
+ print "Unseen node on the tree view\n"
145
+ end
146
+ @selecting = false
147
+ end
148
+
149
+ def showTree
150
+ if parentNode
151
+ parentNode.showTree
152
+ end
153
+ @tree.show if @tree
154
+ end
155
+
156
+ def deselect
157
+ @treeitem.deselect
158
+ childNodes do |node|
159
+ node.deselect
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ ## create XML tree
167
+ builder = XML::DOM::DOMBuilder.new
168
+ builder.setBase("./")
169
+ begin
170
+ xmltree = builder.parse($<.read, PARSE_EXT)
171
+ rescue XML::Parser::Error
172
+ line = builder.line
173
+ print "#{$0}: #{$!} (in line #{line})\n"
174
+ exit 1
175
+ end
176
+ print "Parsing end\n"
177
+ GC.start
178
+
179
+ ## unify sequential Text nodes
180
+ xmltree.documentElement.normalize
181
+ xmltree.trim if TRIM
182
+ print "Normalization end\n"
183
+ GC.start
184
+
185
+ ## create Gtk window
186
+ window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
187
+ window.signal_connect("delete_event") { exit }
188
+ window.signal_connect("destroy_event") { exit }
189
+
190
+ window.border_width(10)
191
+ window.set_title($<.filename)
192
+
193
+ box1 = Gtk::VBox::new(FALSE, 5)
194
+ box1_h = Gtk::HBox::new(FALSE, 5)
195
+ window.add(box1)
196
+ box1.show
197
+ box1.add(box1_h)
198
+ box1_h.show
199
+
200
+ tree = nil
201
+ $text = Gtk::Entry.new()
202
+ box1_h.pack_start($text, TRUE, TRUE, 0)
203
+ $text.show
204
+ button = Gtk::Button::new("Find")
205
+ button.signal_connect("clicked") do
206
+ text = $text.get_text
207
+ xmltree.deselect
208
+ context = XPath::DOM::Context.new(xmltree)
209
+ begin
210
+ tree.set_selection_mode(Gtk::SELECTION_MULTIPLE)
211
+ # proc = XPath.compile(Uconv.euctou8(text))
212
+ proc = XPath.compile(text)
213
+ result = proc.call(context)
214
+ result.each do |node|
215
+ node.selectNode
216
+ end
217
+ rescue
218
+ ## XPath Error
219
+ print "\a#{$!}: #{text}\n"
220
+ ensure
221
+ tree.set_selection_mode(Gtk::SELECTION_SINGLE)
222
+ end
223
+ 1
224
+ end
225
+ box1_h.pack_start(button, FALSE, FALSE, 0)
226
+ button.show
227
+
228
+ scroll = Gtk::ScrolledWindow.new
229
+ scroll.show
230
+ scroll.set_usize(600,400)
231
+ box1.add(scroll)
232
+
233
+
234
+ tree = Gtk::Tree::new()
235
+ ##tree.set_selection_mode(Gtk::SELECTION_MULTIPLE)
236
+ scroll.add_with_viewport(tree) ## gtk+-1.2
237
+ ##scroll.add(tree) ## gtk+-1.0
238
+ tree.show
239
+
240
+ ## construct Gtk tree
241
+ xmltree.newTreeItem(tree)
242
+ print "Tree construction end\n"
243
+
244
+ box2 = Gtk::VBox::new(FALSE, 10)
245
+ box2.border_width(10)
246
+ box1.pack_start(box2, FALSE, TRUE, 0)
247
+ box2.show
248
+
249
+ button = Gtk::Button::new("Quit")
250
+ button.signal_connect("clicked") do
251
+ exit
252
+ end
253
+ box2.pack_start(button, TRUE, TRUE, 0)
254
+ button.show
255
+
256
+
257
+ window.show
258
+ GC.start
259
+ Gtk::main()
@@ -0,0 +1,16 @@
1
+ <!-- NS test -->
2
+ <aa:a xmlns:aa="aaa">
3
+ <a:a xmlns:a="hogeaaa" xmlns:b="gogebbb" xmlns="hoge1">
4
+ <b a="aaaa&amp;&quot;&apos;&#13;
5
+ &#10;&#9;bbbb">
6
+ test&amp;&#10;&#9;test
7
+ <c xmlns="" c="cvccc" c:c="aaaa" xmlns:c="hogeeeee"/>
8
+ </b>
9
+ <b:b xmlns:b="hoge2" b:b="aaa"/>
10
+ <b:b b:b="aaa">
11
+ <c xmlns=""/>
12
+ <b:c b:b="hohoho" xmlns:b=""/>
13
+ test
14
+ </b:b>
15
+ </a:a>
16
+ </aa:a>
@@ -0,0 +1,7 @@
1
+ <?hoge aaa?>
2
+ <!-- saddas -->
3
+ <?hoge?>
4
+ <a xmlns:paa="aaaaa" xmlns:pa='aaaaa' xmlns:pb='aaaaa' xmlns="aaaaa">
5
+ <?hoge?> <!-- saddas -->
6
+ <pa:b><!--&#169;-->&amp;<![CDATA[&amp;hoge]]></pa:b>
7
+ </a>
@@ -0,0 +1,4 @@
1
+ <!ELEMENT test (#PCDATA)>
2
+ <!ATTLIST test qqqq CDATA "QQQQ">
3
+ <!ENTITY % ext2 SYSTEM "ext2.dtd">
4
+ %ext2;
@@ -0,0 +1 @@
1
+ <!ENTITY aaa "AAA">
@@ -0,0 +1,34 @@
1
+ #! /usr/local/bin/ruby
2
+
3
+ require 'xml/parser'
4
+
5
+ class ExtDTDParser < XML::Parser
6
+ def startElement(name, attr)
7
+ p ["startElement", name, attr]
8
+ end
9
+
10
+ def endElement(name)
11
+ p ["endElement", name]
12
+ end
13
+
14
+ def character(data)
15
+ p ["character", data]
16
+ end
17
+
18
+ def externalEntityRef(context, base, systemId, publicId)
19
+ p ["externalEntityRef", context, base, systemId, publicId]
20
+ extp = ExtDTDParser.new(self, context)
21
+ extp.parse(open(systemId).read)
22
+ extp.done ## required
23
+ end
24
+ end
25
+
26
+ p = ExtDTDParser.new(nil, '!')
27
+ if p.respond_to?(:setParamEntityParsing)
28
+ p.setParamEntityParsing(XML::Parser::PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
29
+ end
30
+ begin
31
+ p.parse($<.read)
32
+ rescue XML::Parser::Error
33
+ print "#{$!} in l.#{p.line}\n"
34
+ end
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
2
+ <!DOCTYPE test SYSTEM "ext1.dtd">
3
+ <test>
4
+ &aaa;
5
+ </test>
@@ -0,0 +1,8 @@
1
+ /ext.ent/1.1.1.1/Wed Mar 12 05:51:33 2003//
2
+ /exttest.rb/1.2/Wed Mar 12 06:38:35 2003//
3
+ /exttesti.rb/1.2/Wed Mar 12 06:38:35 2003//
4
+ /hoge.dtd/1.1.1.1/Wed Mar 12 05:51:33 2003//
5
+ /idtest.xml/1.1.1.1/Wed Mar 12 05:51:33 2003//
6
+ /xmlextparser.rb/1.2/Wed Mar 12 06:38:36 2003//
7
+ /idtest.rb/1.3/Wed Feb 18 02:36:52 2004//
8
+ D
@@ -0,0 +1 @@
1
+ /Users/yoshidam/.cvs/xmlparser/samples/expat-1.2
@@ -0,0 +1 @@
1
+ /Users/yoshidam/.cvs
@@ -0,0 +1,2 @@
1
+ <?xml encoding="EUC-JP"?>
2
+ ������
@@ -0,0 +1,82 @@
1
+ #! /usr/local/bin/ruby
2
+
3
+ require 'xmlextparser'
4
+
5
+
6
+ class TestParser < XML::ExtParser
7
+ def externalParsedEntityDecl(entname, base, sysid, pubid)
8
+ p ["externalParsedEntityDecl", entname, base, sysid, pubid]
9
+ end
10
+
11
+ def internalParsedEntityDecl(entname, text)
12
+ p ["internalParsedEntityDecl", entname, text]
13
+ end
14
+
15
+ def escapeAttrVal(str)
16
+ ret = ""
17
+ str.scan(/./um) do |c|
18
+ code = c.unpack("U")[0]
19
+ if code == 9 || code == 10 || code == 13
20
+ ret << sprintf("&#x%X;", code)
21
+ elsif c == "&"
22
+ ret << "&amp;"
23
+ elsif c == "\""
24
+ ret << "&quot;"
25
+ elsif c == "<"
26
+ ret << "&lt;"
27
+ else
28
+ ret << c
29
+ end
30
+ end
31
+ ret
32
+ end
33
+
34
+ def escapeText(str)
35
+ ret = ""
36
+ str.scan(/./um) do |c|
37
+ code = c.unpack("U")[0]
38
+ if code == 13
39
+ ret << sprintf("&#x%X;", code)
40
+ elsif c == "&"
41
+ ret << "&amp;"
42
+ elsif c == "<"
43
+ ret << "&lt;"
44
+ elsif c == ">"
45
+ ret << "&gt;"
46
+ else
47
+ ret << c
48
+ end
49
+ end
50
+ ret
51
+ end
52
+
53
+ def startElement(name, attrs)
54
+ print "<" + name
55
+ attrs.each do |n, v|
56
+ print " " + n + "='" + escapeAttrVal(v) + "'"
57
+ end
58
+ print ">"
59
+ end
60
+
61
+ def endElement(name)
62
+ print "</" + name + ">"
63
+ end
64
+
65
+ def character(text)
66
+ print escapeText(text)
67
+ end
68
+ end
69
+
70
+ p = TestParser.new
71
+
72
+ pos = ARGV[0].rindex("/")
73
+ if pos
74
+ p.setBase(ARGV[0][0, pos + 1])
75
+ else
76
+ p.setBase("")
77
+ end
78
+ begin
79
+ p.parse($<.read)
80
+ rescue XML::Parser::Error
81
+ p([$!, p.line])
82
+ end