Samouczek PHP

Strona główna PHP Wprowadzenie do PHP Instalacja PHP Składnia PHP Komentarze PHP Zmienne PHP PHP Echo / Drukuj Typy danych PHP Ciągi PHP Liczby PHP Matematyka w PHP Stałe PHP Operatory PHP PHP Jeśli...Inne...Elseif Przełącznik PHP Pętle PHP Funkcje PHP Tablice PHP PHP Superglobals PHP RegEx

Formularze PHP

Obsługa formularzy PHP Walidacja formularzy PHP Wymagany formularz PHP Adres URL/e-mail formularza PHP Formularz PHP kompletny

Zaawansowany PHP

Data i godzina w PHP Uwzględnij PHP Obsługa plików PHP Otwórz/odczytaj plik PHP Tworzenie/zapisywanie plików PHP Przesyłanie plików PHP Pliki cookie PHP Sesje PHP Filtry PHP Zaawansowane filtry PHP Funkcje wywołania zwrotnego PHP PHP JSON Wyjątki PHP

PHP OOP

PHP Co to jest OOP Klasy/obiekty PHP Konstruktor PHP Destruktor PHP Modyfikatory dostępu PHP Dziedziczenie PHP Stałe PHP Klasy abstrakcyjne PHP Interfejsy PHP Cechy PHP Metody statyczne PHP Właściwości statyczne PHP Przestrzenie nazw PHP Iterowalne PHP

Baza danych MySQL

Baza danych MySQL Połączenie MySQL Tworzenie bazy danych MySQL Utwórz tabelę MySQL Wstaw dane MySQL Pobierz ostatni identyfikator MySQL Wstaw wiele MySQL Przygotowano MySQL Wybierz dane MySQL MySQL Gdzie Zamów MySQL według Usuń dane MySQL Dane aktualizacji MySQL Dane limitu MySQL

PHP XML

Parsery PHP XML Parser PHP SimpleXML PHP SimpleXML — Get Rozszerzenie PHP XML PHP XML DOM

PHP - AJAX

Wprowadzenie do AJAX AJAX PHP Baza danych AJAX XML AJAX Wyszukiwanie na żywo AJAX Ankieta AJAX

Przykłady PHP

Przykłady PHP Kompilator PHP Quiz PHP Ćwiczenia PHP Certyfikat PHP

Odniesienie do PHP

Przegląd PHP Tablica PHP Kalendarz PHP Data PHP Katalog PHP Błąd PHP Wyjątek PHP System plików PHP Filtr PHP PHP FTP PHP JSON Słowa kluczowe PHP Biblioteka PHP Poczta PHP Matematyka w PHP Różne PHP PHP MySQLi Sieć PHP Kontrola wyjścia PHP PHP RegEx PHP SimpleXML Strumień PHP ciąg PHP Obsługa zmiennych PHP Parser PHP XML Kod pocztowy PHP Strefy czasowe PHP

Funkcja PHP xml_set_element_handler()

❮ Dokumentacja parsera PHP XML

Przykład

Określ funkcje, które mają być wywoływane na początku i na końcu elementu w dokumencie XML ( note.xml ):

<?php
$parser=xml_parser_create();

function start($parser,$element_name,$element_attrs) {
  switch($element_name) {
    case "NOTE":
    echo "NOTE<br>";
    break;
    case "TO":
    echo "To: ";
    break;
    case "FROM":
    echo "From: ";
    break;
    case "HEADING":
    echo "Heading: ";
    break;
    case "BODY":
    echo "Message: ";
  }
}

function stop($parser,$element_name) {
echo "<br>";
}

function char($parser,$data) {
echo $data;
}

//  Specify functions to be called at the start and end of an element in the XML document
xml_set_element_handler($parser,"start","stop");
xml_set_character_data_handler($parser,"char");
$fp=fopen("note.xml","r");

while ($data=fread($fp,4096)) {
  xml_parse($parser,$data,feof($fp)) or
  die (sprintf("XML Error: %s at line %d",
  xml_error_string(xml_get_error_code($parser)),
  xml_get_current_line_number($parser)));
}

xml_parser_free($parser);
fclose($fp);
?>

Definicja i użycie

Funkcja xml_set_element_handler() określa funkcje, które mają być wywoływane na początku i na końcu elementu w dokumencie XML.

Uwaga: Parametry start i end mogą być również tablicą zawierającą odwołanie do obiektu i nazwę metody.

Składnia

xml_set_element_handler(parser, start, end)

Wartości parametrów

Parameter Description
parser Required. Specifies the XML parser to use
start Required. Specifies a function to be called at the start of an element. The function must have three parameters:
  • $parser - A variable containing the XML parser calling the handler
  • $name - A variable containing the name of the elements, that triggers this function, from the XML file as a string
  • $data - An array containing the elements attributes from the XML file as a string
end Required. Specifies a function to be called at the end of an element. The function must have two parameters:
  • $parser - A variable containing the XML parser calling the handler
  • $name - A variable containing the name of the elements, that triggers this function, from the XML file as a string


Szczegóły techniczne

Wartość zwrotu: PRAWDA o sukcesie. FAŁSZ w przypadku niepowodzenia
Wersja PHP: 4.0+

❮ Dokumentacja parsera PHP XML