xref: /PHP-8.4/ext/xml/tests/bug26614.inc (revision 552ea62e)
1<?php
2/*
3this test has different output on libxml2 (even depending on the version) and Expat
4
5further investigation has shown that not only line count
6is skippet on CDATA sections but that libxml does also
7show different column numbers and byte positions depending
8on context and in opposition to what one would expect to
9see and what good old Expat reported just fine ...
10*/
11
12$xmls = array();
13
14// Case 1: CDATA Sections
15$xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
16<data>
17<![CDATA[
18multi
19line
20CDATA
21block
22]]>
23</data>';
24
25// Case 2: replace some characters so that we get comments instead
26$xmls["Comment"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
27<data>
28<!-- ATA[
29multi
30line
31CDATA
32block
33-->
34</data>';
35
36// Case 3: replace even more characters so that only textual data is left
37$xmls["Text"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
38<data>
39-!-- ATA[
40multi
41line
42CDATA
43block
44---
45</data>';
46
47function startElement($parser, $name, $attrs) {
48    printf("<$name> at line %d, col %d (byte %d)\n",
49               xml_get_current_line_number($parser),
50               xml_get_current_column_number($parser),
51               xml_get_current_byte_index($parser));
52}
53
54function endElement($parser, $name) {
55    printf("</$name> at line %d, col %d (byte %d)\n",
56               xml_get_current_line_number($parser),
57               xml_get_current_column_number($parser),
58               xml_get_current_byte_index($parser));
59}
60
61function characterData($parser, $data) {
62  // dummy
63}
64
65foreach ($xmls as $desc => $xml) {
66  echo "$desc\n";
67    $xml_parser = xml_parser_create();
68    xml_set_element_handler($xml_parser, "startElement", "endElement");
69    xml_set_character_data_handler($xml_parser, "characterData");
70    if (!xml_parse($xml_parser, $xml, true))
71        echo "Error: ".xml_error_string(xml_get_error_code($xml_parser))."\n";
72    xml_parser_free($xml_parser);
73}
74