本文整理汇总了PHP中XmlWriter::WritePi方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlWriter::WritePi方法的具体用法?PHP XmlWriter::WritePi怎么用?PHP XmlWriter::WritePi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlWriter
的用法示例。
在下文中一共展示了XmlWriter::WritePi方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: outputXml
function outputXml($results, $xsltPath)
{
/* Setting XML header */
@header("content-type: text/xml; charset=UTF-8");
/* Initializing the XML Object */
$xml = new XmlWriter();
$xml->openMemory();
$xml->setIndent(true);
$xml->setIndentString(' ');
$xml->startDocument('1.0', 'UTF-8');
if (isset($xsltPath)) {
$xml->WritePi('xml-stylesheet', 'type="text/xsl" href="' . $xsltPath . '"');
}
$xml->startElement('callback');
$xml->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->writeAttribute('xsi:noNamespaceSchemaLocation', 'schema.xsd');
/* Function that converts each array element to an XML node */
function write(XMLWriter $xml, $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
if (is_numeric($key)) {
#The only time a numeric key would be used is if it labels an array with non-uniqe keys
write($xml, $value);
continue;
} else {
$xml->startElement($key);
write($xml, $value);
$xml->endElement();
continue;
}
}
$xml->writeElement($key, $value);
}
}
/* Calls previously declared function, passing our results array as parameter */
write($xml, $results);
/* Closing last XML node */
$xml->endElement();
/* Printing the XML */
echo $xml->outputMemory(true);
}