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.
- data/Encodings/README.ja +18 -0
- data/Encodings/euc-jp.enc +0 -0
- data/Encodings/shift_jis.enc +0 -0
- data/History.txt +5 -0
- data/Manifest.txt +118 -0
- data/README +697 -0
- data/README.ja +789 -0
- data/README.txt +49 -0
- data/Rakefile +30 -0
- data/ext/encoding.h +91 -0
- data/ext/extconf.rb +58 -0
- data/ext/xmlparser.c +2231 -0
- data/lib/sax.rb +1 -0
- data/lib/saxdriver.rb +1 -0
- data/lib/wget.rb +47 -0
- data/lib/xml/dom/builder-ja.rb +58 -0
- data/lib/xml/dom/builder.rb +310 -0
- data/lib/xml/dom/core.rb +3276 -0
- data/lib/xml/dom/digest.rb +94 -0
- data/lib/xml/dom/visitor.rb +182 -0
- data/lib/xml/dom2/attr.rb +213 -0
- data/lib/xml/dom2/cdatasection.rb +76 -0
- data/lib/xml/dom2/characterdata.rb +177 -0
- data/lib/xml/dom2/comment.rb +81 -0
- data/lib/xml/dom2/core.rb +19 -0
- data/lib/xml/dom2/document.rb +317 -0
- data/lib/xml/dom2/documentfragment.rb +82 -0
- data/lib/xml/dom2/documenttype.rb +102 -0
- data/lib/xml/dom2/dombuilder.rb +277 -0
- data/lib/xml/dom2/dombuilderfilter.rb +12 -0
- data/lib/xml/dom2/domentityresolver.rb +13 -0
- data/lib/xml/dom2/domentityresolverimpl.rb +37 -0
- data/lib/xml/dom2/domexception.rb +95 -0
- data/lib/xml/dom2/domimplementation.rb +61 -0
- data/lib/xml/dom2/dominputsource.rb +29 -0
- data/lib/xml/dom2/element.rb +533 -0
- data/lib/xml/dom2/entity.rb +110 -0
- data/lib/xml/dom2/entityreference.rb +107 -0
- data/lib/xml/dom2/namednodemap.rb +138 -0
- data/lib/xml/dom2/node.rb +587 -0
- data/lib/xml/dom2/nodelist.rb +231 -0
- data/lib/xml/dom2/notation.rb +86 -0
- data/lib/xml/dom2/processinginstruction.rb +155 -0
- data/lib/xml/dom2/text.rb +128 -0
- data/lib/xml/dom2/xpath.rb +398 -0
- data/lib/xml/encoding-ja.rb +42 -0
- data/lib/xml/parser.rb +13 -0
- data/lib/xml/parserns.rb +236 -0
- data/lib/xml/sax.rb +353 -0
- data/lib/xml/saxdriver.rb +370 -0
- data/lib/xml/xpath.rb +3284 -0
- data/lib/xml/xpath.ry +2352 -0
- data/lib/xmldigest.rb +1 -0
- data/lib/xmlencoding-ja.rb +11 -0
- data/lib/xmltree.rb +1 -0
- data/lib/xmltreebuilder-ja.rb +9 -0
- data/lib/xmltreebuilder.rb +1 -0
- data/lib/xmltreevisitor.rb +1 -0
- data/samples/buildertest.rb +47 -0
- data/samples/buildertest2.rb +50 -0
- data/samples/digesttest.rb +26 -0
- data/samples/digesttest2.rb +192 -0
- data/samples/doctype.rb +40 -0
- data/samples/doctype.xml +21 -0
- data/samples/doctypei.rb +19 -0
- data/samples/document.dtd +77 -0
- data/samples/dom2/dom2test1.rb +7 -0
- data/samples/dom2/dom2test2.rb +10 -0
- data/samples/dom2/gtkxpath.rb +259 -0
- data/samples/dom2/test1.xml +16 -0
- data/samples/dom2/test2.xml +7 -0
- data/samples/dtd/ext1.dtd +4 -0
- data/samples/dtd/ext2.dtd +1 -0
- data/samples/dtd/extdtd.rb +34 -0
- data/samples/dtd/extdtd.xml +5 -0
- data/samples/expat-1.2/CVS/Entries +8 -0
- data/samples/expat-1.2/CVS/Repository +1 -0
- data/samples/expat-1.2/CVS/Root +1 -0
- data/samples/expat-1.2/ext.ent +2 -0
- data/samples/expat-1.2/exttest.rb +82 -0
- data/samples/expat-1.2/exttesti.rb +81 -0
- data/samples/expat-1.2/hoge.dtd +7 -0
- data/samples/expat-1.2/idattr.xml +8 -0
- data/samples/expat-1.2/idtest.rb +21 -0
- data/samples/expat-1.2/idtest.xml +12 -0
- data/samples/expat-1.2/xmlextparser.rb +39 -0
- data/samples/gtktree.rb +146 -0
- data/samples/idattrtest.rb +28 -0
- data/samples/index_euc.xml +72 -0
- data/samples/index_jis.xml +72 -0
- data/samples/index_noenc.xml +71 -0
- data/samples/index_sjis.xml +72 -0
- data/samples/index_u16.xml +0 -0
- data/samples/index_u8.xml +72 -0
- data/samples/my-html.rb +65 -0
- data/samples/namespaces/CVS/Entries +5 -0
- data/samples/namespaces/CVS/Repository +1 -0
- data/samples/namespaces/CVS/Root +1 -0
- data/samples/namespaces/namespace1.rb +29 -0
- data/samples/namespaces/namespace1.xml +10 -0
- data/samples/namespaces/namespace2.rb +41 -0
- data/samples/namespaces/namespace2.xml +12 -0
- data/samples/nstest.rb +21 -0
- data/samples/saxtest.rb +70 -0
- data/samples/test/featurelist.rb +11 -0
- data/samples/test/skippedentity.rb +48 -0
- data/samples/test/useforeigndtd.rb +42 -0
- data/samples/treetest.rb +14 -0
- data/samples/visitor.rb +29 -0
- data/samples/visitortest.rb +36 -0
- data/samples/writer.rb +43 -0
- data/samples/xmlcheck.rb +40 -0
- data/samples/xmlcomments.rb +30 -0
- data/samples/xmlevent.rb +76 -0
- data/samples/xmliter.rb +57 -0
- data/samples/xmlstats.rb +167 -0
- data/samples/xpointer.rb +233 -0
- data/samples/xpointertest.rb +23 -0
- metadata +185 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<!DOCTYPE document SYSTEM "document.dtd">
|
|
2
|
+
|
|
3
|
+
<document>
|
|
4
|
+
<title>よしだむの秘密のページ</title>
|
|
5
|
+
|
|
6
|
+
<para>
|
|
7
|
+
よしだむの秘密のページにようこそ☆
|
|
8
|
+
</para>
|
|
9
|
+
<para>
|
|
10
|
+
このページは HTML4.0,CSS 1.0 に準拠した Web ブラウザで閲覧することを
|
|
11
|
+
お勧めします。
|
|
12
|
+
</para>
|
|
13
|
+
|
|
14
|
+
<index>
|
|
15
|
+
<link xml:link="simple" href="/">[bekkoame ホームページ]</link>
|
|
16
|
+
</index>
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
<section>
|
|
20
|
+
<heading>更新情報</heading>
|
|
21
|
+
<subsection>
|
|
22
|
+
<heading>1998/07/08</heading>
|
|
23
|
+
<list>
|
|
24
|
+
<item>XML2HTML でページを生成するようにしました</item>
|
|
25
|
+
<item>Ruby ページで XMLParser モジュールと Uconv モジュールの公開
|
|
26
|
+
を始めました</item>
|
|
27
|
+
</list>
|
|
28
|
+
</subsection>
|
|
29
|
+
</section>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<section id="hobby">
|
|
33
|
+
<heading>趣味</heading>
|
|
34
|
+
<subsection id="ruby">
|
|
35
|
+
<heading><link xml:link="simple" href="Ruby.html">♪Ruby</link></heading>
|
|
36
|
+
<para>最近は Ruby なのです。</para>
|
|
37
|
+
</subsection>
|
|
38
|
+
|
|
39
|
+
<subsection id="xml">
|
|
40
|
+
<heading><link xml:link="simple" href="XML.html">♪XML</link></heading>
|
|
41
|
+
<para>XML もやってます。</para>
|
|
42
|
+
<list>
|
|
43
|
+
<item>
|
|
44
|
+
<link xml:link="simple" href="index.xml">このページのソース
|
|
45
|
+
(XML)</link>
|
|
46
|
+
</item>
|
|
47
|
+
<item>
|
|
48
|
+
<link xml:link="simple" href="document.dtd">このページの DTD</link>
|
|
49
|
+
</item>
|
|
50
|
+
<item>
|
|
51
|
+
<link xml:link="simple" href="document.css">このページのスタイル
|
|
52
|
+
シート</link>
|
|
53
|
+
</item>
|
|
54
|
+
</list>
|
|
55
|
+
</subsection>
|
|
56
|
+
</section>
|
|
57
|
+
|
|
58
|
+
<section id="misc">
|
|
59
|
+
<heading>その他のページ</heading>
|
|
60
|
+
<list>
|
|
61
|
+
<item><link xml:link="simple" href="http://www.cipuco.net/">
|
|
62
|
+
CIPUCO!!</link></item>
|
|
63
|
+
</list>
|
|
64
|
+
</section>
|
|
65
|
+
|
|
66
|
+
<rpara>
|
|
67
|
+
Copyright 1998 by
|
|
68
|
+
<link xml:link="simple" href="mailto:yoshidam@yoshidam.net">
|
|
69
|
+
Yoshida Masato (yoshidam@yoshidam.net)</link>
|
|
70
|
+
</rpara>
|
|
71
|
+
</document>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="shift_jis"?>
|
|
2
|
+
<!DOCTYPE document SYSTEM "document.dtd">
|
|
3
|
+
|
|
4
|
+
<document>
|
|
5
|
+
<title>�悵���ނ̔閧�̃y�[�W</title>
|
|
6
|
+
|
|
7
|
+
<para>
|
|
8
|
+
�悵���ނ̔閧�̃y�[�W�ɂ悤������
|
|
9
|
+
</para>
|
|
10
|
+
<para>
|
|
11
|
+
���̃y�[�W�� HTML4.0�CCSS 1.0 �ɏ������� Web �u���E�U�ʼn{�����邱�Ƃ�
|
|
12
|
+
�����߂��܂��B
|
|
13
|
+
</para>
|
|
14
|
+
|
|
15
|
+
<index>
|
|
16
|
+
<link xml:link="simple" href="/">[bekkoame �z�[���y�[�W]</link>
|
|
17
|
+
</index>
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
<section>
|
|
21
|
+
<heading>�X�V���</heading>
|
|
22
|
+
<subsection>
|
|
23
|
+
<heading>1998/07/08</heading>
|
|
24
|
+
<list>
|
|
25
|
+
<item>XML2HTML �Ńy�[�W������悤�ɂ��܂���</item>
|
|
26
|
+
<item>Ruby �y�[�W�� XMLParser ���W���[���� Uconv ���W���[���̌��J
|
|
27
|
+
���n�߂܂���</item>
|
|
28
|
+
</list>
|
|
29
|
+
</subsection>
|
|
30
|
+
</section>
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
<section id="hobby">
|
|
34
|
+
<heading>�</heading>
|
|
35
|
+
<subsection id="ruby">
|
|
36
|
+
<heading><link xml:link="simple" href="Ruby.html">��Ruby</link></heading>
|
|
37
|
+
<para>�ŋ߂� Ruby �Ȃ̂ł��B</para>
|
|
38
|
+
</subsection>
|
|
39
|
+
|
|
40
|
+
<subsection id="xml">
|
|
41
|
+
<heading><link xml:link="simple" href="XML.html">��XML</link></heading>
|
|
42
|
+
<para>XML ������Ă܂��B</para>
|
|
43
|
+
<list>
|
|
44
|
+
<item>
|
|
45
|
+
<link xml:link="simple" href="index.xml">���̃y�[�W�̃\�[�X
|
|
46
|
+
(XML)</link>
|
|
47
|
+
</item>
|
|
48
|
+
<item>
|
|
49
|
+
<link xml:link="simple" href="document.dtd">���̃y�[�W�� DTD</link>
|
|
50
|
+
</item>
|
|
51
|
+
<item>
|
|
52
|
+
<link xml:link="simple" href="document.css">���̃y�[�W�̃X�^�C��
|
|
53
|
+
�V�[�g</link>
|
|
54
|
+
</item>
|
|
55
|
+
</list>
|
|
56
|
+
</subsection>
|
|
57
|
+
</section>
|
|
58
|
+
|
|
59
|
+
<section id="misc">
|
|
60
|
+
<heading>���̑��̃y�[�W</heading>
|
|
61
|
+
<list>
|
|
62
|
+
<item><link xml:link="simple" href="http://www.cipuco.net/">
|
|
63
|
+
CIPUCO!!</link></item>
|
|
64
|
+
</list>
|
|
65
|
+
</section>
|
|
66
|
+
|
|
67
|
+
<rpara>
|
|
68
|
+
Copyright 1998 by
|
|
69
|
+
<link xml:link="simple" href="mailto:yoshidam@yoshidam.net">
|
|
70
|
+
Yoshida Masato (yoshidam@yoshidam.net)</link>
|
|
71
|
+
</rpara>
|
|
72
|
+
</document>
|
|
Binary file
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<?xml version="1.0"?>
|
|
2
|
+
<!DOCTYPE document SYSTEM "document.dtd">
|
|
3
|
+
|
|
4
|
+
<document>
|
|
5
|
+
<title>よしだむの秘密のページ</title>
|
|
6
|
+
|
|
7
|
+
<para>
|
|
8
|
+
よしだむの秘密のページにようこそ☆
|
|
9
|
+
</para>
|
|
10
|
+
<para>
|
|
11
|
+
このページは HTML4.0,CSS 1.0 に準拠した Web ブラウザで閲覧することを
|
|
12
|
+
お勧めします。
|
|
13
|
+
</para>
|
|
14
|
+
|
|
15
|
+
<index>
|
|
16
|
+
<link xml:link="simple" href="/">[bekkoame ホームページ]</link>
|
|
17
|
+
</index>
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
<section>
|
|
21
|
+
<heading>更新情報</heading>
|
|
22
|
+
<subsection>
|
|
23
|
+
<heading>1998/07/08</heading>
|
|
24
|
+
<list>
|
|
25
|
+
<item>XML2HTML でページを生成するようにしました</item>
|
|
26
|
+
<item>Ruby ページで XMLParser モジュールと Uconv モジュールの公開
|
|
27
|
+
を始めました</item>
|
|
28
|
+
</list>
|
|
29
|
+
</subsection>
|
|
30
|
+
</section>
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
<section id="hobby">
|
|
34
|
+
<heading>趣味</heading>
|
|
35
|
+
<subsection id="ruby">
|
|
36
|
+
<heading><link xml:link="simple" href="Ruby.html">♪Ruby</link></heading>
|
|
37
|
+
<para>最近は Ruby なのです。</para>
|
|
38
|
+
</subsection>
|
|
39
|
+
|
|
40
|
+
<subsection id="xml">
|
|
41
|
+
<heading><link xml:link="simple" href="XML.html">♪XML</link></heading>
|
|
42
|
+
<para>XML もやってます。</para>
|
|
43
|
+
<list>
|
|
44
|
+
<item>
|
|
45
|
+
<link xml:link="simple" href="index.xml">このページのソース
|
|
46
|
+
(XML)</link>
|
|
47
|
+
</item>
|
|
48
|
+
<item>
|
|
49
|
+
<link xml:link="simple" href="document.dtd">このページの DTD</link>
|
|
50
|
+
</item>
|
|
51
|
+
<item>
|
|
52
|
+
<link xml:link="simple" href="document.css">このページのスタイル
|
|
53
|
+
シート</link>
|
|
54
|
+
</item>
|
|
55
|
+
</list>
|
|
56
|
+
</subsection>
|
|
57
|
+
</section>
|
|
58
|
+
|
|
59
|
+
<section id="misc">
|
|
60
|
+
<heading>その他のページ</heading>
|
|
61
|
+
<list>
|
|
62
|
+
<item><link xml:link="simple" href="http://www.cipuco.net/">
|
|
63
|
+
CIPUCO!!</link></item>
|
|
64
|
+
</list>
|
|
65
|
+
</section>
|
|
66
|
+
|
|
67
|
+
<rpara>
|
|
68
|
+
Copyright 1998 by
|
|
69
|
+
<link xml:link="simple" href="mailto:yoshidam@yoshidam.net">
|
|
70
|
+
Yoshida Masato (yoshidam@yoshidam.net)</link>
|
|
71
|
+
</rpara>
|
|
72
|
+
</document>
|
data/samples/my-html.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#! /usr/local/bin/ruby
|
|
2
|
+
|
|
3
|
+
## Visitor test
|
|
4
|
+
## 1998 by yoshidam
|
|
5
|
+
##
|
|
6
|
+
## This sample comes from Ken MacLeod's sample of XML-Grove-0.05
|
|
7
|
+
## Copyright (C) 1998 Ken MacLeod
|
|
8
|
+
|
|
9
|
+
require 'xml/dom/builder'
|
|
10
|
+
require 'xml/dom/visitor'
|
|
11
|
+
|
|
12
|
+
class MyHTML<XML::DOM::Visitor
|
|
13
|
+
def visit_Document(document, *rest)
|
|
14
|
+
document.children_accept_name(self, *rest)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def visit_Element(element, *rest)
|
|
18
|
+
raise "visit_Element called while using accept_name??\n"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def visit_EntityReference(eref, *rest)
|
|
22
|
+
print "&#{eref.nodeName};"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def visit_Text(text, *rest)
|
|
26
|
+
print text.nodeValue
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def visit_name_DATE(element, *rest)
|
|
30
|
+
print Time.new.to_s.gsub!(/ /, " ")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def visit_name_PERL(element, *rest)
|
|
34
|
+
print "I cannot execute Perl scripts!!\n"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def visit_name_RUBY(element, *rest)
|
|
38
|
+
script = ''
|
|
39
|
+
element.childNodes.each do |node|
|
|
40
|
+
script += node.nodeValue
|
|
41
|
+
end
|
|
42
|
+
begin
|
|
43
|
+
eval(script)
|
|
44
|
+
rescue
|
|
45
|
+
print "Ruby error: #{$!}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def method_missing(mid, *rest)
|
|
51
|
+
if mid.id2name =~ /^visit_name_(.+)$/
|
|
52
|
+
name = $1
|
|
53
|
+
element = rest.shift
|
|
54
|
+
print "<#{name}>"
|
|
55
|
+
element.children_accept_name(self, *rest)
|
|
56
|
+
print "</#{name}>"
|
|
57
|
+
else
|
|
58
|
+
raise NameError.new("undefined method `#{mid.id2name}' " +
|
|
59
|
+
"for #{self.inspect}")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
doc = XML::DOM::Builder.new.parse($<.read)
|
|
65
|
+
doc.accept_name(MyHTML.new, [])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/Users/yoshidam/.cvs/xmlparser/samples/namespaces
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/Users/yoshidam/.cvs
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#! /usr/local/bin/ruby
|
|
2
|
+
|
|
3
|
+
require 'xml/parser'
|
|
4
|
+
|
|
5
|
+
def default; end
|
|
6
|
+
|
|
7
|
+
p = XML::Parser.new(nil, ":")
|
|
8
|
+
#def p.startNamespaceDecl() end
|
|
9
|
+
#def p.endNamespaceDecl() end
|
|
10
|
+
p.parse($<.read) do |type, name, data|
|
|
11
|
+
case (type)
|
|
12
|
+
when XML::Parser::START_ELEM
|
|
13
|
+
attr = ''
|
|
14
|
+
data.each do |key, value|
|
|
15
|
+
attr += " #{key}=\"#{value}\""
|
|
16
|
+
end
|
|
17
|
+
print "<#{name}#{attr}>"
|
|
18
|
+
when XML::Parser::END_ELEM
|
|
19
|
+
print "</#{name}>"
|
|
20
|
+
when XML::Parser::CDATA
|
|
21
|
+
print data
|
|
22
|
+
# when XML::Parser::START_NAMESPACE_DECL
|
|
23
|
+
# print "start NS: #{name}, #{data}\n"
|
|
24
|
+
# when XML::Parser::END_NAMESPACE_DECL
|
|
25
|
+
# print "start NS: #{name}\n"
|
|
26
|
+
else
|
|
27
|
+
print data
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0"?>
|
|
2
|
+
|
|
3
|
+
<test xmlns="http://www.yoshidam.net/ns/hoge/"
|
|
4
|
+
xmlns:ns2="http://www.yoshidam.net/ns/hoge2/"
|
|
5
|
+
attr="No default namespace"
|
|
6
|
+
ns2:attr="ns2 namespace">
|
|
7
|
+
<aa>Default name space</aa>
|
|
8
|
+
<aa xmlns="">No deafult namespace</aa>
|
|
9
|
+
<ns2:aa xmlns="">ns2 namespace</ns2:aa>
|
|
10
|
+
</test>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#! /usr/local/bin/ruby
|
|
2
|
+
|
|
3
|
+
require 'xml/parser'
|
|
4
|
+
|
|
5
|
+
module XML
|
|
6
|
+
class Parser
|
|
7
|
+
def initialize(encoding = nil, nssep = nil)
|
|
8
|
+
@nstbl = {nil=>""}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def startElement(name, attr)
|
|
12
|
+
name =~ /^(([^;]*);)?(.+)$/
|
|
13
|
+
uri = $2
|
|
14
|
+
prefix = @nstbl[uri] || ""
|
|
15
|
+
name = $3
|
|
16
|
+
uri = uri || ""
|
|
17
|
+
print "(" + prefix + "[" + uri + "]:" + name + "\n"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def endElement(name)
|
|
21
|
+
name =~ /^(([^;]*);)?(.+)$/
|
|
22
|
+
uri = $2
|
|
23
|
+
prefix = @nstbl[uri] || ""
|
|
24
|
+
name = $3
|
|
25
|
+
uri = uri || ""
|
|
26
|
+
print ")" + prefix + "[" + uri + "]:" + name + "\n"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def startNamespaceDecl(prefix, uri)
|
|
30
|
+
prefix = "" if prefix.nil?
|
|
31
|
+
uri = uri || ""
|
|
32
|
+
@nstbl[uri] = prefix
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def endNamespaceDecl(prefix)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
p = XML::Parser.new(nil, ";")
|
|
41
|
+
p.parse($<.read)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0"?>
|
|
2
|
+
<!DOCTYPE test [
|
|
3
|
+
<!ELEMENT test (aa)*>
|
|
4
|
+
<!ATTLIST test xmlns CDATA #IMPLIED>
|
|
5
|
+
<!ELEMENT aa (bb)*>
|
|
6
|
+
<!ELEMENT bb (cc)*>
|
|
7
|
+
<!ELEMENT cc EMPTY>
|
|
8
|
+
]>
|
|
9
|
+
|
|
10
|
+
<test xmlns="http://www.yoshidam.net/ns/hoge/">
|
|
11
|
+
<aa><bb><cc/></bb></aa>
|
|
12
|
+
</test>
|
data/samples/nstest.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#! /usr/local/bin/ruby
|
|
2
|
+
|
|
3
|
+
require 'xml/parserns'
|
|
4
|
+
|
|
5
|
+
p = XML::ParserNS.new()
|
|
6
|
+
def p.startElement(n, a)
|
|
7
|
+
p(["start", resolveElementQName(n)])
|
|
8
|
+
a.each do | n, v|
|
|
9
|
+
p(['attr', resolveAttributeQName(n), v])
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def p.endElement(n)
|
|
14
|
+
p(["end", resolveElementQName(n)])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
p.parse($<.read)
|
|
18
|
+
# do |t, n, d|
|
|
19
|
+
# p([t, n, d])
|
|
20
|
+
#end
|
|
21
|
+
|
data/samples/saxtest.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#! /usr/local/bin/ruby
|
|
2
|
+
|
|
3
|
+
## SAX test
|
|
4
|
+
## 1999 yoshidam
|
|
5
|
+
|
|
6
|
+
require 'xml/saxdriver'
|
|
7
|
+
|
|
8
|
+
class TestHandler < XML::SAX::HandlerBase
|
|
9
|
+
def getPos
|
|
10
|
+
[@locator.getSystemId, @locator.getLineNumber]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def getAttrs(attrs)
|
|
14
|
+
ret = []
|
|
15
|
+
for i in 0...attrs.getLength
|
|
16
|
+
ret .push([attrs.getName(i), attrs.getValue(i)])
|
|
17
|
+
end
|
|
18
|
+
ret
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def startDocument
|
|
22
|
+
p ["startDocument", getPos]
|
|
23
|
+
end
|
|
24
|
+
def endDocument
|
|
25
|
+
p ["endDocument", getPos]
|
|
26
|
+
end
|
|
27
|
+
def startElement(name, attr)
|
|
28
|
+
p ["startElement", name, getAttrs(attr), getPos]
|
|
29
|
+
end
|
|
30
|
+
def endElement(name)
|
|
31
|
+
p ["endElement", name, getPos]
|
|
32
|
+
end
|
|
33
|
+
def characters(ch, start, length)
|
|
34
|
+
p ["characters", ch[start, length], getPos]
|
|
35
|
+
end
|
|
36
|
+
def processingInstruction(target, data)
|
|
37
|
+
p ["processingInstruction", target, data, getPos]
|
|
38
|
+
end
|
|
39
|
+
def notationDecl(name, pubid, sysid)
|
|
40
|
+
p ["notationDecl", name, pubid, sysid, getPos]
|
|
41
|
+
end
|
|
42
|
+
def unparsedEntityDecl(name, pubid, sysid, notation)
|
|
43
|
+
p ["unparsedEntityDecl", name, pubid, sysid, notation, getPos]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def resolveEntity(pubid, sysid)
|
|
47
|
+
p ["resolveEntity", pubid, sysid]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def setDocumentLocator(loc)
|
|
51
|
+
@locator = loc
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def fatalError(e)
|
|
55
|
+
print "*** FATAL ERROR ***\n"
|
|
56
|
+
raise e
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
p = XML::SAX::Helpers::ParserFactory.makeParser("XML::Parser::SAXDriver")
|
|
61
|
+
h = TestHandler.new
|
|
62
|
+
p.setDocumentHandler(h)
|
|
63
|
+
p.setDTDHandler(h)
|
|
64
|
+
p.setEntityResolver(h)
|
|
65
|
+
p.setErrorHandler(h)
|
|
66
|
+
begin
|
|
67
|
+
p.parse(ARGV[0])
|
|
68
|
+
rescue XML::SAX::SAXParseException
|
|
69
|
+
p(["ParseError", $!.getSystemId, $!.getLineNumber, $!.getMessage])
|
|
70
|
+
end
|