PHP - Fonction xmlwriter_end_comment ()

Définition et utilisation

XML est un langage de balisage permettant de partager les données sur le Web, XML est à la fois lisible par l'homme et par machine. L'extension XMLWriter a en interne l'API libxml xmlWriter et est utilisée pour écrire / créer le contenu d'un document XML. Les documents XML générés par celui-ci ne sont pas mis en cache et uniquement en avant.

le xmlwriter_end_comment() La fonction accepte un objet de la classe XMLWriter et termine la balise de commentaire actuelle.

Syntaxe

xmlwriter_end_comment($writer);

Paramètres

Sr. Non Paramètre et description
1

writer(Mandatory)

Il s'agit d'un objet de la classe XMLWriter représentant le document XML que vous souhaitez modifier / créer.

Valeurs de retour

Cette fonction renvoie une valeur booléenne qui est TRUE en cas de succès et FALSE en cas d'échec.

Version PHP

Cette fonction a été introduite pour la première fois dans la version 5 de PHP et fonctionne dans toutes les versions ultérieures.

Exemple

L'exemple suivant montre l'utilisation du xmlwriter_end_comment() fonction -

<?php
   //Creating an XMLWriter
   $writer = new XMLWriter();

   //Opening a writer
   $uri = "result.xml";
   $writer = xmlwriter_open_uri($uri);

   //Starting the document
   xmlwriter_start_document($writer);

   //Starting an element
   xmlwriter_start_element($writer, 'Msg');
    
   //Starting the comment 
   xmlwriter_start_comment($writer); 
     
   //Setting value to the comment
   xmlwriter_text($writer, 'This is a sample comment'); 
     
   //Ending the comment 
   xmlwriter_end_comment($writer); 

   //Adding text to the element
   xmlwriter_text($writer, 'Welcome to Tutorialspoint');  

   //Starting an element
   xmlwriter_end_element($writer);

   //Ending the document
   xmlwriter_end_document($writer);
?>

Cela générera le document XML suivant -

<?xml version="1.0"?>
<Msg><!--This is a sample comment-->Welcome to Tutorialspoint</Msg>

Exemple

Voici l'exemple de cette fonction dans le style orienté objet -

<?php
   //Creating an XMLWriter
   $writer = new XMLWriter();

   //Opening a writer
   $uri = "result.xml";
   $writer->openUri($uri);

   //Starting the document
   $writer->startDocument();

   //Starting an element
   $writer->startElement('Msg');

   //Starting the comment 
   $writer->startComment(); 
     
   //Setting value to the comment
   $writer->text('This is a sample comment'); 
     
   //Ending the comment 
   $writer->endComment(); 

   //Adding text to the element
   $writer->text('Welcome to Tutorialspoint');  

   //Ending the element
   $writer->endElement();

   //Ending the document
   $writer->endDocument();
?>

Cela générera le document XML suivant -

<?xml version="1.0"?>
<Msg><!--This is a sample comment-->Welcome to Tutorialspoint</Msg>