本文整理汇总了PHP中XMLWriter::startAttributeNS方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLWriter::startAttributeNS方法的具体用法?PHP XMLWriter::startAttributeNS怎么用?PHP XMLWriter::startAttributeNS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLWriter
的用法示例。
在下文中一共展示了XMLWriter::startAttributeNS方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: XMLWriter
<?php
/* $Id$ */
$xw = new XMLWriter();
$xw->openMemory();
$xw->setIndent(TRUE);
$xw->setIndentString(' ');
$xw->startDocument('1.0', "UTF-8");
$xw->startElement('root');
$xw->startElementNS('ns1', 'child1', 'urn:ns1');
$xw->startAttributeNS('ns1', 'att1', 'urn:ns1');
$xw->text('a&b');
$xw->endAttribute();
$xw->writeAttribute('att2', "double\" single'");
$xw->startAttributeNS('ns1', 'att2', 'urn:ns1');
$xw->text("<>\"'&");
$xw->endAttribute();
$xw->writeElement('chars', "special characters: <>\"'&");
$xw->endElement();
$xw->endDocument();
// Force to write and empty the buffer
$output = $xw->flush(true);
print $output;
示例2: ExportToRss
/**
* Used to export the given data as rss feed
*
* It returns a xml data string containing rss feed data
*
* @link http://www.w3schools.com/xml/xml_syntax.asp
* @param array $data the data to be exported to rss format
* @param array $xml_namespace the xml namespace for the document
* prefix => string the xml namespace prefix
* name => string the xml namespace name
* uri => string the xml namespace uri
* @param array $namespace_attributes the list of tags that need to be prefixed with namespace
*
* @return string $rss_file the contents of the rss file
*/
public function ExportToRss($data, $xml_namespace, $namespace_attributes)
{
/** The XMLWriter class object is created. The XMLWriter php extension is enabled by default */
$writer = new \XMLWriter();
$writer->openMemory();
/** The xml prolog is added */
$writer->startDocument('1.0', 'UTF-8');
$writer->setIndent(true);
$writer->startAttributeNS($xml_namespace['prefix'], $xml_namespace['name'], $xml_namespace['uri']);
/** The rss tag is opened */
$writer->startElement('rss');
$writer->startAttribute('version');
$writer->text('2.0');
$writer->endAttribute();
$writer->startElement('channel');
/** Each Item is added to the rss feed */
for ($count = 0; $count < count($data); $count++) {
$data_item = $data[$count];
$writer->startElement('item');
/** Xml tag is created for each data item */
foreach ($data_item as $tag_name => $tag_value) {
/** If the tag name is in the list of tags that need to be prefixed with namespace */
if (in_array($tag_name, $namespace_attributes)) {
/** The namespace is added to the tag name */
$tag_name = $xml_namespace['name'] . ":" . $tag_name;
}
$writer->startElement($tag_name);
$writer->text($tag_value);
$writer->endElement();
}
$writer->endElement();
}
$writer->endElement();
$writer->endElement();
$writer->endDocument();
/** The xml data is exported to string */
$rss_file = $writer->outputMemory(TRUE);
return $rss_file;
}
示例3: startAttributeNS
/**
* @param string $prefix
* @param string $name
* @param string $uri
* @return bool
*/
public function startAttributeNS($prefix, $name, $uri = null)
{
$this->nsArray[$prefix] = $uri;
return parent::startAttributeNS($prefix, $name, $uri);
}