30
30
@testset " XML" begin
31
31
valid_file = joinpath (dirname (@__FILE__ ), " sample1.xml" )
32
32
invalid_file = joinpath (dirname (@__FILE__ ), " sample1.invalid.xml" )
33
- doc = read (EzXML . Document, valid_file)
33
+ doc = readxml ( valid_file)
34
34
@test isa (doc, EzXML. Document)
35
35
@test nodetype (doc. node) === EzXML. DOCUMENT_NODE
36
36
@test nodetype (readxml (valid_file). node) === EzXML. DOCUMENT_NODE
37
- @test_throws EzXML. XMLError read (EzXML . Document, invalid_file)
37
+ @test_throws EzXML. XMLError readxml ( invalid_file)
38
38
@assert ! isfile (" not-exist.xml" )
39
- @test_throws EzXML. XMLError read (EzXML. Document, " not-exist.xml" )
40
39
@test_throws EzXML. XMLError readxml (" not-exist.xml" )
41
40
42
41
# from compressed file
43
42
compressed = joinpath (dirname (@__FILE__ ), " sample1.xml.gz" )
44
- @test isa (read (EzXML. Document, compressed), EzXML. Document)
45
43
@test isa (readxml (compressed), EzXML. Document)
46
44
47
45
# from stream
53
51
54
52
@testset " HTML" begin
55
53
valid_file = joinpath (dirname (@__FILE__ ), " sample1.html" )
56
- doc = read (EzXML . Document, valid_file)
54
+ doc = readhtml ( valid_file)
57
55
@test isa (doc, EzXML. Document)
58
56
@test nodetype (doc. node) === EzXML. HTML_DOCUMENT_NODE
59
57
@test nodetype (readhtml (valid_file). node) === EzXML. HTML_DOCUMENT_NODE
60
58
@assert ! isfile (" not-exist.html" )
61
- @test_throws EzXML. XMLError read (EzXML . Document, " not-exist.html" )
59
+ @test_throws EzXML. XMLError readxml ( " not-exist.html" )
62
60
@test_throws EzXML. XMLError readhtml (" not-exist.html" )
63
61
64
62
# from compressed file
65
63
compressed = joinpath (dirname (@__FILE__ ), " sample1.html.gz" )
66
- @test isa (read (EzXML . Document, compressed), EzXML. Document)
64
+ @test isa (readxml ( compressed), EzXML. Document)
67
65
@test isa (readhtml (compressed), EzXML. Document)
68
66
69
67
# from stream (FIXME : this causes "Misplaced DOCTYPE declaration")
101
99
<foo>ok</foo>
102
100
</root>
103
101
"""
104
- doc = parse (EzXML . Document, docstr)
102
+ doc = parsexml ( docstr)
105
103
tmp = tempname ()
106
104
try
107
105
@test write (tmp, doc) == sizeof (docstr)
108
106
@test String (read (tmp)) == docstr
109
- @test string (read (EzXML . Document, tmp)) == docstr
107
+ @test string (readxml ( tmp)) == docstr
110
108
finally
111
109
rm (tmp)
112
110
end
113
111
end
114
112
115
113
@testset " Parser" begin
116
114
@testset " XML" begin
117
- doc = parse (EzXML . Document, """
115
+ doc = parsexml ( """
118
116
<?xml version="1.0"?>
119
117
<root>
120
118
<child attr="value">content</child>
@@ -123,15 +121,15 @@ end
123
121
@test isa (doc, EzXML. Document)
124
122
@test nodetype (doc. node) === EzXML. DOCUMENT_NODE
125
123
126
- doc = parse (EzXML . Document, """
124
+ doc = parsexml ( """
127
125
<root>
128
126
<child attr="value">content</child>
129
127
</root>
130
128
""" )
131
129
@test isa (doc, EzXML. Document)
132
130
@test nodetype (doc. node) === EzXML. DOCUMENT_NODE
133
131
134
- doc = parse (EzXML . Document, b """
132
+ doc = parsexml ( b """
135
133
<?xml version="1.0"?>
136
134
<root>
137
135
<child attr="value">content</child>
145
143
@test nodetype (parsexml (b " <html/>" ). node) === EzXML. DOCUMENT_NODE
146
144
147
145
# This includes multi-byte characters.
148
- doc = parse (EzXML . Document, """
146
+ doc = parsexml ( """
149
147
<?xml version="1.0" encoding="UTF-8" ?>
150
148
<Link>
151
149
<Name>pubmed_pubmed</Name>
@@ -156,17 +154,17 @@ end
156
154
""" )
157
155
@test nodetype (doc. node) === EzXML. DOCUMENT_NODE
158
156
159
- @test_throws ArgumentError parse (EzXML . Document, " " )
160
- @test_throws EzXML. XMLError parse (EzXML . Document, " " )
161
- @test_throws EzXML. XMLError parse (EzXML . Document, " abracadabra" )
162
- @test_throws EzXML. XMLError parse (EzXML . Document, """ <?xml version="1.0"?>""" )
157
+ @test_throws ArgumentError parsexml ( " " )
158
+ @test_throws EzXML. XMLError parsexml ( " " )
159
+ @test_throws EzXML. XMLError parsexml ( " abracadabra" )
160
+ @test_throws EzXML. XMLError parsexml ( """ <?xml version="1.0"?>""" )
163
161
164
162
info (" the following warning is expected:" )
165
163
@test_throws EzXML. XMLError parsexml (" <gepa?>jgo<<<><<" )
166
164
end
167
165
168
166
@testset " HTML" begin
169
- doc = parse (EzXML . Document, """
167
+ doc = parsehtml ( """
170
168
<!DOCTYPE html>
171
169
<html>
172
170
<head>
182
180
@test hasdtd (doc)
183
181
@test nodename (dtd (doc)) == " html"
184
182
185
- doc = parse (EzXML . Document, """
183
+ doc = parsehtml ( """
186
184
<html>
187
185
<head>
188
186
<title>Title</title>
196
194
@test nodetype (doc. node) === EzXML. HTML_DOCUMENT_NODE
197
195
@test hasdtd (doc)
198
196
199
- doc = parse (EzXML . Document, b """
197
+ doc = parsehtml ( b """
200
198
<!DOCTYPE html>
201
199
<html>
202
200
<head>
523
521
@test_throws ArgumentError systemID (root (doc))
524
522
@test_throws ArgumentError externalID (root (doc))
525
523
526
- doc = parse (EzXML . Document, """
524
+ doc = parsexml ( """
527
525
<?xml version="1.0"?>
528
526
<r>
529
527
<c1/>
558
556
@test_throws ArgumentError prevelement (c1)
559
557
@test_throws ArgumentError nextelement (c3)
560
558
561
- doc = parse (EzXML . Document, """
559
+ doc = parsexml ( """
562
560
<?xml version="1.0"?>
563
561
<root attr="some attribute value"><child>some content</child></root>
564
562
""" )
571
569
@test ! haskey (root (doc), " attr" )
572
570
@test_throws KeyError root (doc)[" attr" ]
573
571
574
- doc = parse (EzXML . Document, " <root/>" )
572
+ doc = parsexml ( " <root/>" )
575
573
x = root (doc)
576
574
@test_throws ArgumentError firstnode (x)
577
575
@test_throws ArgumentError lastnode (x)
698
696
@test_throws ArgumentError namespace (root (doc))
699
697
700
698
@testset " Counters" begin
701
- doc = parse (EzXML . Document, " <root/>" )
699
+ doc = parsexml ( " <root/>" )
702
700
@test ! hasnode (root (doc))
703
701
@test countnodes (root (doc)) === 0
704
702
@test countelements (root (doc)) === 0
716
714
end
717
715
718
716
@testset " Iterators" begin
719
- doc = parse (EzXML . Document, " <root/>" )
717
+ doc = parsexml ( " <root/>" )
720
718
ns = EzXML. Node[]
721
719
for (i, node) in enumerate (eachnode (root (doc)))
722
720
@test isa (node, EzXML. Node)
732
730
@test length (ns) == 0
733
731
@test elements (root (doc)) == ns
734
732
735
- doc = parse (EzXML . Document, """
733
+ doc = parsexml ( """
736
734
<root><c1></c1><c2></c2></root>
737
735
""" )
738
736
ns = EzXML. Node[]
750
748
@test length (ns) == 2
751
749
@test elements (root (doc)) == ns
752
750
753
- doc = parse (EzXML . Document, """
751
+ doc = parsexml ( """
754
752
<root>
755
753
<c1></c1>
756
754
<c2></c2>
771
769
@test length (ns) == 2
772
770
@test elements (root (doc)) == ns
773
771
774
- doc = parse (EzXML . Document, """
772
+ doc = parsexml ( """
775
773
<root>
776
774
<c1/>
777
775
<c2/>
783
781
@test nodes (root (doc), true ) == reverse (nodes (root (doc)))
784
782
@test elements (root (doc), true ) == reverse (elements (root (doc)))
785
783
786
- doc = parse (EzXML . Document, """
784
+ doc = parsexml ( """
787
785
<?xml version="1.0"?>
788
786
<root attr1="foo" attr2="bar"></root>
789
787
""" )
883
881
@test t2. owner === e2
884
882
@test a1. owner === e2
885
883
886
- doc = parse (EzXML . Document, " <root/>" )
884
+ doc = parsexml ( " <root/>" )
887
885
@test isempty (nodes (root (doc)))
888
886
c1 = ElementNode (" c1" )
889
887
link! (root (doc), c1)
918
916
@test root (doc) == el
919
917
@test [(nodename (n), nodecontent (n)) for n in attributes (root (doc))] == [(" attr1" , " 1" ), (" attr2" , " 2" )]
920
918
921
- doc = parse (EzXML . Document, """
919
+ doc = parsexml ( """
922
920
<root></root>
923
921
""" )
924
922
@test string (doc. node) == """
944
942
<root><child1>some text</child1><child2/><!--some comment--><![CDATA[<cdata>]]></root>
945
943
"""
946
944
947
- doc = parse (EzXML . Document, """
945
+ doc = parsexml ( """
948
946
<?xml version="1.0" encoding="UTF-8"?>
949
947
<root>
950
948
<c1>
962
960
@test c1. owner == c1
963
961
@test c2. owner == c1
964
962
965
- doc = parse (EzXML . Document, """
963
+ doc = parsexml ( """
966
964
<root xmlns:x="http://xxx.org/" xmlns:y="http://yyy.org/">
967
965
<c x:attr="x-attr" y:attr="y-attr"/>
968
966
<c y:attr="y-attr" x:attr="x-attr"/>
0 commit comments