當前位置: 首頁>>代碼示例>>PHP>>正文


PHP XMLWriter::startAttributeNS方法代碼示例

本文整理匯總了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;
開發者ID:badlamer,項目名稱:hhvm,代碼行數:23,代碼來源:OO_007.php

示例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;
 }
開發者ID:Negative-Network,項目名稱:Pak-PHP,代碼行數:54,代碼來源:String.php

示例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);
 }
開發者ID:dcarbone,項目名稱:xml-writer-plus,代碼行數:11,代碼來源:XMLWriterPlus.php


注:本文中的XMLWriter::startAttributeNS方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。