PHP handleiding

PHP TUIS PHP Inleiding PHP installeer PHP sintaksis PHP opmerkings PHP veranderlikes PHP Echo / Druk PHP datatipes PHP Strings PHP-nommers PHP Wiskunde PHP konstante PHP-operateurs PHP As...Anders...Elseif PHP skakelaar PHP-lusse PHP funksies PHP-skikkings PHP Superglobals PHP RegEx

PHP- vorms

PHP-vormhantering PHP-vorm validering PHP-vorm word vereis PHP-vorm URL/e-pos PHP-vorm voltooi

PHP Gevorderd

PHP datum en tyd PHP sluit in PHP-lêerhantering PHP-lêer oop/lees PHP-lêer skep/skryf PHP-lêer oplaai PHP-koekies PHP-sessies PHP filters PHP-filters Gevorderd PHP-terugbelfunksies PHP JSON PHP-uitsonderings

PHP OOP

PHP Wat is OOP PHP Klasse/Objekte PHP Konstrukteur PHP vernietiger PHP Toegangswysigers PHP erfenis PHP konstante PHP Abstrakte Klasse PHP-koppelvlakke PHP eienskappe PHP statiese metodes PHP Statiese Eienskappe PHP naamruimtes PHP Iterables

MySQL- databasis

MySQL-databasis MySQL Connect MySQL Skep DB MySQL Skep tabel MySQL Voeg data in MySQL Kry Laaste ID MySQL Voeg veelvuldige in MySQL voorberei MySQL Kies Data MySQL Waar MySQL Bestel deur MySQL verwyder data MySQL-opdateringsdata MySQL-limietdata

PHP XML

PHP XML-ontleders PHP SimpleXML-ontleder PHP SimpleXML - Kry PHP XML Expat PHP XML DOM

PHP - AJAX

AJAX Intro AJAX PHP AJAX-databasis AJAX XML AJAX Live Search AJAX-peiling

PHP voorbeelde

PHP voorbeelde PHP samesteller PHP vasvra PHP Oefeninge PHP-sertifikaat

PHP- verwysing

PHP Oorsig PHP Skikking PHP-kalender PHP datum PHP gids PHP fout PHP-uitsondering PHP lêerstelsel PHP filter PHP FTP PHP JSON PHP sleutelwoorde PHP Libxml PHP-pos PHP Wiskunde PHP Diverse PHP MySQLi PHP-netwerk PHP-uitsetbeheer PHP RegEx PHP SimpleXML PHP-stroom PHP-string PHP veranderlike hantering PHP XML-ontleder PHP zip PHP Tydsones

PHP simplexml_load_file() Funksie

❮ PHP SimpleXML-verwysing

Voorbeeld

Omskep 'n XML-lêer in 'n voorwerp, voer dan sleutels en elemente van die voorwerp uit:

<?php
$xml=simplexml_load_file("note.xml");
print_r($xml);
?>

Definisie en gebruik

Die simplexml_load_file()-funksie skakel 'n XML-dokument om na 'n objek.


Sintaksis

simplexml_load_file(file, class, options, ns, is_prefix)

Parameterwaardes

Parameter Description
file Required. Specifies the path to the XML file
class Optional. Specifies the class of the new object
options Optional. Specifies additional Libxml parameters. Is set by specifying the option and 1 or 0 (TRUE or FALSE, e.g. LIBXML_NOBLANKS(1))

Possible values:

  • LIBXML_COMPACT - Activate nodes allocation optimization (may speed up application)
  • LIBXML_DTDATTR - Set default DTD attributes
  • LIBXML_DTDLOAD - Load external subset
  • LIBXML_DTDVALID - Validate with the DTD
  • LIBXML_NOBLANKS - Remove blank nodes
  • LIBXML_NOCDATA - Merge CDATA as text nodes
  • LIBXML_NOEMPTYTAG - Expand empty tags (e.g. <br/> to <br></br>), only available in the DOMDocument->save() and DOMDocument->saveXML() functions
  • LIBXML_NOENT - Substitute entities
  • LIBXML_NOERROR - Do not show error reports
  • LIBXML_NONET - Disable network access while loading documents
  • LIBXML_NOWARNING - Do not show warning reports
  • LIBXML_NOXMLDECL - Drop the XML declaration when saving a document
  • LIBXML_NSCLEAN - Remove redundant namespace declarations
  • LIBXML_PARSEHUGE - Sets XML_PARSE_HUGE flag, which relaxes any hardcoded limit from the parser. This affects limits like maximum depth of a document and limits of the size of text nodes
  • LIBXML_XINCLUDE - Implement XInclude substitution
  • LIBXML_ERR_ERROR - Get recoverable errors
  • LIBXML_ERR_FATAL - Get fatal errors
  • LIBXML_ERR_NONE - Get no errors
  • LIBXML_ERR_WARNING - Get simple warnings
  • LIBXML_VERSION - Get libxml version (e.g. 20605 or 20617)
  • LIBXML_DOTTED_VERSION - Get dotted libxml version (e.g. 2.6.5 or 2.6.17)
ns Optional. Specifies a namespace prefix or URI
is_prefix Optional. Specifies a Boolean value. TRUE if ns is a prefix. FALSE if ns is a URI. Default is FALSE


Tegniese besonderhede

Terugkeerwaarde: 'n SimpleXMLElement-objek oor sukses. ONWAAR op mislukking
PHP weergawe: 5+

Meer voorbeelde

Gestel ons het die volgende XML-lêer, " note.xml ":

<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

Voorbeeld

Voer die data van elke element in die XML-lêer uit:

<?php
$xml=simplexml_load_file("note.xml");
echo $xml->to . "<br>";
echo $xml->from . "<br>";
echo $xml->heading . "<br>";
echo $xml->body;
?>

Voorbeeld

Voer die element se naam en data uit vir elke kindnodus in die XML-lêer:

<?php
$xml=simplexml_load_file("note.xml");
echo $xml->getName() . "<br>";

foreach($xml->children() as $child)
  {
  echo $child->getName() . ": " . $child . "<br>";
  }
?>

❮ PHP SimpleXML-verwysing