PCCS MySQLDatabase Admin Tool version 1.3.4


/xml/ -> xmlparse.php

1 
2 
3  <?php
4  print '
5  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
6  <HTML lang="en">
7  <HEAD>
8  <TITLE>XML&nbsp;Parser</TITLE>
9  </HEAD>
10  <BODY>';
11          // Hacked this script from various snippets of code...
12          //handler for the start elements
13          function beginElement($parser, $name, $attribs)
14          {
15                  if (strtolower($name) == "row")
16                  {
17                          //handler for the row element
18                          print "<tr>";
19                  }
20                  if (strtolower($name) == "column")
21                  {
22                          //handler for the column
23                          print "<td>";
24                  }
25                  if (strtolower($name) == "error")
26                  {
27                          //handler for the error
28                          print "<tr><td>";
29                  }
30                  if (strtolower($name) == "result")
31                  {
32                          print "<br><table border=0 cellpadding=2 cellspacing=0>";
33                  }
34          }
35 
36          //handler for the end of elements
37          function endElement($parser, $name)
38          {
39                  if (strtolower($name) == "row")
40                  {
41                          //handler for the row element
42                          print "</tr>";
43                  }
44                  if (strtolower($name) == "column")
45                  {
46                          //handler for the column
47                          print "</td>";
48                  }
49                  if (strtolower($name) == "error")
50                  {
51                          //handler for the error
52                          print "</td></tr>";
53                  }
54                  if (strtolower($name) == "result")
55                  {
56                          print "</table> <br>";
57                  }
58          }
59 
60          //handler for character data
61          function characterData($parser, $data)
62          {
63                  print "$data";
64          }
65 
66          // $xml_file = 'this.xml';
67          
68          // declare the character set - UTF-8 is the default
69          $type = 'UTF-8';
70          
71          // create our parser
72          $xml_parser = xml_parser_create($type);
73          
74          // set some parser options
75          // enable case-folding for this parser
76          xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
77          
78          // set source encoding for this parser
79          xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
80 
81 
82          //parse the XML
83          $xml_parser = xml_parser_create();
84          
85          // set up start and end element handlers
86          xml_set_element_handler($xml_parser, "beginElement", "endElement");
87          
88          // set up character data handler
89          xml_set_character_data_handler($xml_parser, "characterData");
90                        
91 
92          if (!($fp = fopen($xml_file, 'r'))) {
93           die("Could not$xml_file for parsing!\n");
94          }
95 
96          // loop through the file and parse!
97          while ($data = fread($fp, 4096)) {
98           if (!($data = utf8_encode($data))) {
99           echo 'ERROR'."\n";
100           }
101           if (!xml_parse($xml_parser, $data, feof($fp))) {
102           die(sprintf( "XML error: %s at line %d\n\n",
103           xml_error_string(xml_get_error_code($xml_parser)),
104           xml_get_current_line_number($xml_parser)));
105           }
106          }
107          // Free this XML parser
108          xml_parser_free($xml_parser);
109          
110  print '
111  </BODY>
112  </HTML>';
113  ?>


Generated: Sat Jan 27 15:40:36 2001 Generated by PHPXref 0.1.2
PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002