62
62
my @badWFStrings = (
63
63
"", # totally empty document
64
64
XML_DECL, # only XML Declaration
65
"<!--ouch-->", # comment only is like an empty document
65
"<!--ouch-->", # comment only is like an empty document
66
66
'<!DOCTYPE ouch [<!ENTITY foo "bar">]>', # no good either ...
67
67
"<ouch>", # single tag (tag mismatch)
68
68
"<ouch/>foo", # trailing junk
75
75
"<ouch>&foo;</ouch>", # undefind entity
76
76
"<ouch>></ouch>", # unterminated entity
77
77
XML_DECL. '<!DOCTYPE foobar [<!ENTITY foo "bar">]><foobar &foo;="ouch"/>', # bad placed entity
78
XML_DECL. '<!DOCTYPE foobar [<!ENTITY foo "bar="foo"">]><foobar &foo;/>', # even worse
78
XML_DECL. '<!DOCTYPE foobar [<!ENTITY foo "bar="foo"">]><foobar &foo;/>', # even worse
79
79
"<ouch><!---></ouch>", # bad comment
80
80
'<ouch><!-----></ouch>', # bad either... (is this conform with the spec????)
221
221
my $doc = $parser->parse_file($goodfile);
222
222
isa_ok($doc, 'XML::LibXML::Document');
225
225
eval {my $fail = $parser->parse_file($badfile1);};
226
226
like($@, qr/^$badfile1:3: parser error : Extra content at the end of the document/, "error parsing $badfile1");
327
327
like($@, qr/$badfile1:3: parser error : Extra content at the end of the document/, "error parsing $badfile1 in include");
328
328
is($doc, undef, "no doc returned");
331
331
eval{ $parser->processXIncludes(undef); };
332
332
like($@, qr/^No document to process! at/, "Error parsing undef include");
341
341
my $pparser = XML::LibXML->new();
342
342
# 2.1 PARSING WELLFORMED DOCUMENTS
343
foreach my $key ( qw(single1 single2 single3 single4 single5 single6
343
foreach my $key ( qw(single1 single2 single3 single4 single5 single6
344
344
single7 single8 single9 multiple1 multiple2 multiple3
345
multiple4 multiple5 multiple6 multiple7 multiple8
345
multiple4 multiple5 multiple6 multiple7 multiple8
346
346
multiple9 multiple10 comment1 comment2 comment3
347
347
comment4 comment5 attr1 attr2 attr3
348
348
ns1 ns2 ns3 ns4 ns5 ns6 dtd1 dtd2) ) {
359
359
my @good_strings = ("<foo>", "bar", "</foo>" );
361
361
predocend1 => ["<A>" ],
362
362
predocend2 => ["<A>", "B"],
363
363
predocend3 => ["<A>", "<C>"],
479
479
my $root = $doc->documentElement;
481
481
# bad thing: i have to do some NS normalizing.
482
# libxml2 will only do some fixing. this will lead to multiple
482
# libxml2 will only do some fixing. this will lead to multiple
483
483
# declarations, if a node with a new namespace is added.
485
485
my $vstring = q{<foo xmlns:bar="http://foo.bar">bar<bar:bi/></foo>};
539
539
wellformed7 => '<A><K/></A>',
540
540
wellformed8 => '<A xmlns="xml://E"/>',
541
541
wellformed9 => '<F:A xmlns:F="xml://G" F:A="B">D</F:A>',
542
wellformed10 => '<!--D-->',
543
wellformed11 => '<A xmlns:F="xml://E"/>',
542
wellformed10 => '<!--D-->',
543
wellformed11 => '<A xmlns:F="xml://E"/>',
544
544
wellbalance1 => '<A/><A/>',
545
545
wellbalance2 => '<A></A><A></A>',
546
546
wellbalance3 => '<A B="C"/><A B="H"/>',
549
549
wellbalance6 => '<A><![CDATA[D]]></A><A><![CDATA[I]]></A>',
550
550
wellbalance7 => '<A><!--D--></A><A><!--I--></A>',
551
551
wellbalance8 => '<F:A xmlns:F="xml://G" F:A="B">D</F:A><J:A xmlns:J="xml://G" J:A="M">D</J:A>',
552
wellbalance9 => 'D<A/>',
552
wellbalance9 => 'D<A/>',
553
553
wellbalance10=> 'D<A/>D',
554
554
wellbalance11=> 'D<A/><!--D-->',
555
555
wellbalance12=> 'D<A/><![CDATA[D]]>',
792
792
is( $parser->parse_string( $xsDoc1 )->documentElement->toString(),
793
793
q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
794
is( $parser->parse_string( $xsDoc2 )->documentElement->toString(),
797
is( $parser->parse_file( $fn1 )->documentElement->toString(),
798
q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
799
is( $parser->parse_file( $fn2 )->documentElement->toString() ,
802
my $fh1 = IO::File->new($fn1);
803
my $fh2 = IO::File->new($fn2);
805
is( $parser->parse_fh( $fh1 )->documentElement->toString(),
806
q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
807
is( $parser->parse_fh( $fh2 )->documentElement->toString() ,
794
is( $parser->parse_string( $xsDoc2 )->documentElement->toString(),
797
is( $parser->parse_file( $fn1 )->documentElement->toString(),
798
q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
799
is( $parser->parse_file( $fn2 )->documentElement->toString() ,
802
my $fh1 = IO::File->new($fn1);
803
my $fh2 = IO::File->new($fn2);
805
is( $parser->parse_fh( $fh1 )->documentElement->toString(),
806
q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
807
is( $parser->parse_fh( $fh2 )->documentElement->toString() ,
810
810
my @xaDoc1 = ('<A:B xmlns:A="http://D">','<A:C xmlns:A="h','ttp://D"/>' ,'</A:B>');
816
816
$parser->parse_chunk( $_ );
818
818
$doc = $parser->parse_chunk( "", 1 );
819
is( $doc->documentElement->toString(),
819
is( $doc->documentElement->toString(),
820
820
q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
824
824
$parser->parse_chunk( $_ );
826
826
$doc = $parser->parse_chunk( "", 1 );
827
is( $doc->documentElement->toString() ,
827
is( $doc->documentElement->toString() ,
840
840
my $parser = XML::LibXML->new();
842
842
$parser->load_ext_dtd(1);
844
844
# first time it should work
845
845
my $doc = $parser->parse_string( $xmldoc );
846
846
is( $doc->documentElement()->string_value(), " test " );
848
# second time it must not fail.
848
# second time it must not fail.
849
849
my $doc2 = $parser->parse_string( $xmldoc );
850
850
is( $doc2->documentElement()->string_value(), " test " );
854
# Test ticket #7668 xinclude breaks entity expansion
854
# Test ticket #7668 xinclude breaks entity expansion
855
855
# [CG] removed again, since #7668 claims the spec is incorrect