📜  PHP | XMLWriter startAttributeNs()函数

📅  最后修改于: 2022-05-13 01:56:51.643000             🧑  作者: Mango

PHP | XMLWriter startAttributeNs()函数

XMLWriter::startAttributeNs()函数是PHP中的一个内置函数,用于启动命名空间属性。稍后可以使用XMLWriter::endAttribute()函数关闭此属性。通常样式网页在命名空间属性中不起作用。

句法:

bool XMLWriter::startAttributeNs( string $prefix, 
string $name, string $uri )

参数:此函数接受三个参数,如上所述,如下所述:

  • $prefix:它指定命名空间的前缀。
  • $name:它指定命名空间的名称。
  • $uri:它指定命名空间的值。

返回值:此函数在成功时返回 TRUE,在失败时返回 FALSE。

下面的示例说明了PHP中的XMLWriter::startAttributeNs()函数

示例 1:

openURI('php://output');
   
// Start the document
$writer->startDocument('1.0', 'UTF-8');
   
// Start a element
$writer->startElement('div');
   
// Start the namespaced attribute
$writer->startAttributeNs('pre', 'attrib', 'value');
   
// Add value to the attribute
$writer->text('value');
   
// End the attribute
$writer->endAttribute();
   
// End the element
$writer->endElement();
   
// End the document
$writer->endDocument();
?>

输出:


示例 2:

openURI('php://output');
   
// Start the document
$writer->startDocument('1.0', 'UTF-8');
   
// Start a element
$writer->startElement('div');
   
// Start the namespaced attribute with style attribute
// This will not work because it is namespaced
$writer->startAttributeNs('style', 'attrib', 'value');
   
// Add value to the attribute
$writer->text('color:blue');
   
// End the attribute
$writer->endAttribute();
  
// Add value to the element
$writer->text('Namespaced GeeksforGeeks');
   
// End the element
$writer->endElement();
  
// Start a h1 element
$writer->startElement('h1');
   
// Start the style attribute
$writer->startAttribute('style');
   
// Add value to the attribute
$writer->text('color:green');
   
// End the attribute
$writer->endAttribute();
   
// Add value to the element
$writer->text('Normal GeeksforGeeks');
   
// End the element
$writer->endElement();
   
// End the document
$writer->endDocument();
?>

输出:

参考: https://www. PHP.net/manual/en/函数.xmlwriter-start-attribute-ns。 PHP