1<?php
2$xml = <<<HERE
3<aw1:book xmlns:aw1="http://www.somewhere.com/namespace1"
4          xmlns:aw2="file:/DTD/somewhere.dtd">
5<aw1:para>Any old text.</aw1:para>
6<aw2:td>An HTML table cell.</aw2:td>
7</aw1:book>
8HERE;
9
10$parser = xml_parser_create_ns();
11xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
12
13var_dump(xml_set_start_namespace_decl_handler( $parser, "Namespace_Start_Handler" ));
14var_dump(xml_set_end_namespace_decl_handler( $parser, "Namespace_End_Handler" ));
15
16xml_parse( $parser, $xml, true);
17xml_parser_free( $parser );
18
19echo "Done\n";
20
21function Namespace_Start_Handler( $parser, $prefix, $uri ) {
22    echo "Namespace_Start_Handler called\n";
23    echo "...Prefix: ". $prefix . "\n";
24    echo "...Uri: ". $uri . "\n";
25}
26
27function Namespace_End_Handler($parser, $prefix) {
28    echo "Namespace_End_Handler called\n";
29    echo "...Prefix: ". $prefix . "\n\n";
30}
31
32function DefaultHandler( $parser, $data ) {
33   print( 'DefaultHandler Called<br/>' );
34}