當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP xmlwriter_end_comment()用法及代碼示例


定義和用法

XML 是一種 mark-up 語言,用於在網絡上共享數據,XML 用於人類 read-able 和機器 read-able。 XMLWriter 擴展內部具有 libxml xmlWriter API,用於編寫/創建 XML 文檔的內容。由此生成的 XML 文檔是非緩存的和 forward-only。

這個xmlwriter_end_comment()函數接受 XMLWriter 類的對象並結束當前注釋標記。

用法

xmlwriter_end_comment($writer);

參數

Sr.No 參數及說明
1

writer(Mandatory)

這是 XMLWriter 類的一個對象,表示您要修改/創建的 XML 文檔。

返回值

此函數返回一個布爾值,成功時為 TRUE,失敗時為 FALSE。

PHP版本

這個函數最初是在 PHP 版本 5 中引入的,並且適用於所有後續版本。

示例

下麵的例子演示了xmlwriter_end_comment()函數 -

<?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);
?>

這將生成以下 XML 文檔 -

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

示例

以下是麵向對象風格的此函數的示例 -

<?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();
?>

這將生成以下 XML 文檔 -

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

相關用法


注:本文由純淨天空篩選整理自 PHP - xmlwriter_end_comment() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。