当前位置: 首页>>代码示例>>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;未经允许,请勿转载。