PHP - xmlwriter_start_dtd_entity() 函数



定义和用法

XML 是一种用于在网络上共享数据的标记语言,XML 既可供人类阅读,也可供机器阅读。XMLWriter 扩展内部具有 libxml xmlWriter API,用于编写/创建 XML 文档的内容。由此生成的 XML 文档是非缓存的且仅向前。

xmlwriter_start_dtd_entity() 函数接受 XMLWriter 类的对象、表示实体名称的字符串值和布尔值作为参数,并创建一个 DTD 实体开始标签。

语法

xmlwriter_start_dtd_entity($writer, $name, $isParam);

参数

序号 参数及描述
1

writer(必填)

这是 XMLWriter 类的一个对象,表示您要修改/创建的 XML 文档。

2

name(必填)

这是一个字符串值,表示文档类型的限定名称。

3

isParam(必填)

这是一个布尔值,指定当前实体是否为参数。

返回值

此函数返回一个布尔值,成功时为 TRUE,失败时为 FALSE。

PHP 版本

此函数首次引入于 PHP 5 版本,并在所有后续版本中均有效。

示例

以下示例演示了 xmlwriter_start_dtd_entity() 函数的用法:

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

   //Starting the document
   xmlwriter_start_document($writer);

   //Setting the indentation
   xmlwriter_set_indent($writer, TRUE);
   xmlwriter_set_indent_string($writer, "    ");

   //Creating a DTD entity start tag
   xmlwriter_start_dtd_entity($writer, 'test_entity', TRUE);

   //Ending the DTD entity end tag
   xmlwriter_end_dtd_entity($writer);
   xmlwriter_start_element($writer, 'address');

   //Starting a element tag
   xmlwriter_start_element($writer, 'name');
   
   //Adding text to the element
   xmlwriter_text($writer, 'Tanmay Patil');  
   xmlwriter_end_element($writer);
   xmlwriter_start_element($writer, 'company');
   
   //Adding text to the element
   xmlwriter_text($writer, 'TutorialsPoint');  
   xmlwriter_end_element($writer);
   xmlwriter_start_element($writer, 'phone');
   
   //Adding text to the element
   xmlwriter_text($writer, '(011) 123-4567');  
   xmlwriter_end_element($writer);

   //Ending the element
   xmlwriter_end_element($writer);

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

这将生成以下 XML 文档:

<?xml version="1.0"?>
<!ENTITY % test_entity>
<address>
   <name>Tanmay Patil</name>
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</address>

示例

以下是此函数在面向对象样式中的示例:

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

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

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

   //Setting the indentation on
   $writer->setIndent(TRUE);
   
   //Setting the indentation
   $writer->setIndentString("    ");

   //Creating a DTD entity start tag
   $writer->startDtdEntity('test_entity', TRUE);

   //Ending the DTD entity end tag
   $writer->endDtdEntity();

   //Starting an element
   $writer->startElement('Tutorial');
   $writer->startElement('name');
   
   //Adding text to the element
   $writer->text('JavaFX');  
   $writer->endElement();
   $writer->startElement('Author');
   
   //Adding text to the element
   $writer->text('Krishna');  
   $writer->endElement();

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

这将生成以下 XML 文档:

<?xml version="1.0"?>
<!ENTITY % test_entity>
<Tutorial>
   <name>JavaFX</name>
   <Author>Krishna</Author>
</Tutorial>
php_function_reference.htm
广告