www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP setting XML node and element handlers (Zend Certification)

  1. #1
    Join Date
    Apr 2006
    Posts
    245

    Question PHP setting XML node and element handlers (Zend Certification)

    I have just sat, and passed, another mock exam for the Zend PHP certification.

    However, the following question came up in the test and I wondered if anyone would be
    able to help me out in obtaining the answers and the reasons (if possible). :-)

    Consider the following code segment:

    PHP Code:
    <?php
    $xmldata 
    = <<< XML
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE html
         PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
        <title>XML Example</title>
      </head>
      <body>
        <p>
          Moved to &lt;<a href="http://example.org/">http://www.example.org/</a>.&gt;
          <br/>
        </p>
      </body>
    </html>
    XML;

    $xml xml_parser_create("UTF-8");

    /* ??????? */

    xml_parse($xml$xmldata);

    function 
    xml_start_handler($xml$tag$attributes) {
        print 
    "Tag: $tag<br/>\n";
    }

    function 
    xml_end_handler($xml$tag) {

    }

    ?>
    What should be placed in place of ?????? above to have the above script display the name of each tag within the XML document?

    The possible answers are:

    • xml_set_callback("xml_start_handler");
    • xml_set_element_handler($xml, "xml_start_handler", "xml_end_handler");
    • xml_node_set_handler("xml_start_handler", "xml_end_handler");
    • xml_node_set_handler("xml_start_handler");


    Cheers,
    Picco

  2. #2
    Join Date
    Apr 2006
    Posts
    245
    I think i've found the answer to this via the PHP documentation.

    xml_set_element_handler appears to be the correct answer, primarily because the other three options don't exist in the PHP documentation.

    http://uk.php.net/manual/en/function...nt-handler.php

    Sets the element handler functions for the XML parser. start_element_handler and end_element_handler are strings containing the names of functions that must exist when xml_parse() is called for parser.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles