Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: XMLWriter 関数 - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

XMLWriter::endAttribute" width="11" height="7"/> <XMLReader::XML
Last updated: Thu, 31 May 2007

view this page in

CLXXXII. XMLWriter 関数

導入

これは、XMLWriter 拡張モジュールです。 libxml の xmlWriter API をラップしています。

この拡張モジュールは、キャッシュ処理をしない前進のみのライターで、 XML データを含むストリームあるいはファイルを作成します。

この拡張モジュールは、オブジェクト指向形式と手続き型のどちらでも使用可能です。 全メソッドについて、その両方のコール方法を説明しています。

定義済みクラス

XMLWriter

メソッド

リソース型

手続き型の XMLWriter 拡張モジュールでは、一種類のリソースを使用します。 これは、xmlwriter_open_memory() あるいは xmlwriter_open_uri() が返すものです。

定義済み定数

定数は定義されていません。

目次

XMLWriter::endAttribute — 属性を終了する
XMLWriter::endCData — 現在の CDATA を終了する
XMLWriter::endComment — コメントの終了部を作成する
XMLWriter::endDocument — 現在のドキュメントを終了する
XMLWriter::endDTDAttlist — 現在の DTD 属性リストを終了する
XMLWriter::endDTDElement — 現在の DTD 要素を終了する
XMLWriter::endDTDEntity — 現在の DTD エンティティを終了する
XMLWriter::endDTD — 現在の DTD を終了する
XMLWriter::endElement — 現在の要素を終了する
XMLWriter::endPI — 現在の PI (処理命令) を終了する
XMLWriter::flush — 現在のバッファをフラッシュする
XMLWriter::fullEndElement — 現在の要素を終了する
XMLWriter::openMemory — 文字列の出力にメモリを使用する新しい xmlwriter を作成する
XMLWriter::openURI — ソース URI を指定して新しい xmlwriter を作成する
XMLWriter::outputMemory — 現在のバッファを返す
XMLWriter::setIndentString — 字下げに使用する文字列を設定する
XMLWriter::setIndent — 字下げの on/off を切り替える
XMLWriter::startAttributeNS — 名前空間つきの属性を開始する
XMLWriter::startAttribute — 属性を開始する
XMLWriter::startCData — CDATA の開始タグを作成する
XMLWriter::startComment — コメントを開始する
XMLWriter::startDocument — ドキュメントタグを作成する
XMLWriter::startDTDAttlist — DTD 属性リストを開始する
XMLWriter::startDTDElement — DTD 要素を開始する
XMLWriter::startDTDEntity — DTD エンティティを開始する
XMLWriter::startDTD — DTD の開始タグを作成する
XMLWriter::startElementNS — 名前空間つき要素の開始タグを作成する
XMLWriter::startElement — 要素の開始タグを作成する
XMLWriter::startPI — PI (処理命令) の開始タグを作成する
XMLWriter::text — テキストを書き込む
XMLWriter::writeAttributeNS — 名前空間つき属性全体を書き込む
XMLWriter::writeAttribute — 属性全体を書き込む
XMLWriter::writeCData — CDATA タグ全体を書き込む
XMLWriter::writeComment — コメントタグ全体を書き込む
XMLWriter::writeDTDAttlist — DTD 属性リストタグ全体を書き込む
XMLWriter::writeDTDElement — DTD 要素タグ全体を書き込む
XMLWriter::writeDTDEntity — DTD エンティティタグ全体を書き込む
XMLWriter::writeDTD — DTD タグ全体を書き込む
XMLWriter::writeElementNS — 名前空間つき要素タグ全体を書き込む
XMLWriter::writeElement — 要素タグ全体を書き込む
XMLWriter::writePI — PI (処理命令) 書き込む
XMLWriter::writeRaw — 生の XML テキストを書き込む


add a note add a note User Contributed Notes
XMLWriter 関数
Yves Sucaet
25-Jul-2007 11:10
If you want your XML-output to be seen as XML by the browser, you need to modify your header. The XmlWriter does not do this for you! Therefore, the first line of your script should be:

header("Content-type: text/xml");
robajz [a] robajz [.] info
20-Nov-2006 06:23
Hi,

There already is a class xmlWriter, although it is not documented. This is a rewrite of the example from [http://cz2.php.net/manual/en/ref.xmlwriter.php#64484 Carlos Averett] and works well on my php 5.1.6

<?php
    $xw
= new xmlWriter();
   
$xw->openMemory();
   
   
$xw->startDocument('1.0','UTF-8');
   
$xw->startDtd('html','-//WAPFORUM//DTD XHTML Mobile 1.0//EN', 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd');
   
$xw->endDtd();
   
$xw->startElement ('html'); // <html>
   
$xw->writeAttribute( 'xmlns', 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd');
   
$xw->writeAttribute( 'xm:lang', 'en');
  
   
$xw->startElement('head'); // <head>
   
   
$xw->writeElement ('title', 'Test WAP Document');
   
   
$xw->endElement(); // </head>
   
$xw->startElement('body'); // <body>
   
$xw->startElement('ol'); // <ol>
   
   
$xw->writeElement ('li', 'One Item &amp;  <sss <ss />></ss>');
   
$xw->writeElement ('li', 'Another Item');
   
$xw->writeElement ('li', 'Another Item');
   
   
$xw->endElement(); // </ol>
   
$xw->endElement(); // </body>
   
$xw->endElement(); // </html>
   
   
$xw->endDtd();
    print
$xw->outputMemory(true);   
?>
Alexandre Arica
16-Apr-2006 09:25
How to generate a simple XML document for a XSL-Transformation purpose.

We have 3 files:
- 'index.php' : output a XML document
- 'XmlConstruct.class.php' : allow to construct a XML document with 'xmlwriter'
- 'index.xsl' : contains a XSLT document

Contents of the file 'index.php' :

<?php
$contents
= array('page_title' => 'Generate a XHTML page from XML+XSLT files',
                   
'welcome_msg' => 'Simple XHTML document from XML+XSLT files!');

require(
'XmlConstruct.class.php');
$XmlConstruct = new XmlConstruct('rootElement', 'index.xsl');
$XmlConstruct->fromArray($contents);
$XmlConstruct->output();
?>

Contents of the file  'XmlConstruct.class.php' :

<?php

/**
 * Construct a simple XML document.
 * This class inherits from the (PHP) class 'xmlwriter'.
 * You will need at least PHP 5.1.2
 *
 * @author Alexandre Arica
 * @since  16 April 2006
 * @version 1.0 modified the 16 April 2006
 */
class XmlConstruct extends XMLWriter
{

   
/**
     * Constructor.
     * @param string $prm_rootElementName A root element's name of a current xml document
     * @param string $prm_xsltFilePath Path of a XSLT file.
     * @access public
     * @param null
     */
   
public function __construct($prm_rootElementName, $prm_xsltFilePath=''){
       
$this->openMemory();
       
$this->setIndent(true);
       
$this->setIndentString(' ');
       
$this->startDocument('1.0', 'UTF-8');

        if(
$prm_xsltFilePath){
           
$this->writePi('xml-stylesheet', 'type="text/xsl" href="'.$prm_xsltFilePath.'"');
        }

       
$this->startElement($prm_rootElementName);
    }

   
/**
     * Set an element with a text to a current xml document.
     * @access public
     * @param string $prm_elementName An element's name
     * @param string $prm_ElementText An element's text
     * @return null
     */
   
public function setElement($prm_elementName, $prm_ElementText){
       
$this->startElement($prm_elementName);
       
$this->text($prm_ElementText);
       
$this->endElement();
    }

   
/**
     * Construct elements and texts from an array.
     * The array should contain an attribute's name in index part
     * and a attribute's text in value part.
     * @access public
     * @param array $prm_array Contains attributes and texts
     * @return null
     */
   
public function fromArray($prm_array){
        if(
is_array($prm_array)){
            foreach (
$prm_array as $index => $text){
               
$this->setElement($index, $text);
            }
        }
    }

   
/**
     * Return the content of a current xml document.
     * @access public
     * @param null
     * @return string Xml document
     */
   
public function getDocument(){
       
$this->endElement();
       
$this->endDocument();
        return
$this->outputMemory();
    }

   
/**
     * Output the content of a current xml document.
     * @access public
     * @param null
     */
   
public function output(){
       
header('Content-type: text/xml');
        echo
$this->getDocument();
    }
   

}

?>

Contents of the file 'index.xsl' :

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet
 version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns="http://www.w3.org/TR/xhtml1/strict">

<xsl:output
    method="html"
    encoding="utf-8"
/>

<xsl:template match="rootElement">

<html xmlns="http://www.w3.org/1999/xhtml">

        <head>

            <title><xsl:value-of select="page_title" /></title>

        </head>
       
        <body>

            <xsl:value-of select="welcome_msg" />

        </body>
       
</html>

</xsl:template>

</xsl:stylesheet>
Carlos Averett
16-Apr-2006 02:49
Using XMLWriter to create a WAP page:

<?php
$memory
= xmlwriter_open_memory();
xmlwriter_start_document($memory,'1.0','UTF-8');
xmlwriter_start_dtd($memory,'html','-//WAPFORUM//DTD XHTML Mobile 1.0//EN', 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd');
xmlwriter_end_dtd($memory);
xmlwriter_start_element ($memory,'html'); // <html>
xmlwriter_write_attribute( $memory, 'xmlns', 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd');
xmlwriter_write_attribute( $memory, 'xm:lang', 'en');

xmlwriter_start_element($memory,'head'); // <head>

xmlwriter_write_element ($memory,'title', 'Test WAP Document');

xmlwriter_end_element($memory); // </head>
xmlwriter_start_element($memory,'body'); // <body>
xmlwriter_start_element($memory,'ol'); // <ol>

xmlwriter_write_element ($memory,'li', 'One Item');
xmlwriter_write_element ($memory,'li', 'Another Item');
xmlwriter_write_element ($memory,'li', 'Another Item');

xmlwriter_end_element($memory); // </ol>
xmlwriter_end_element($memory); // </body>
xmlwriter_end_element($memory); // </html>

xmlwriter_end_dtd($memory);
$xml = xmlwriter_output_memory($memory,true);
?>

Output:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.wapforum.org/DTD/xhtml-mobile10.dtd" xm:lang="en">
<head>
<title>Test WAP Document</title>
</head>
<body>
<ol>
<li>One Item</li>
<li>Another Item</li>
<li>Another Item</li>
</ol>
</body>
</html>

 
show source | credits | sitemap | contact | advertising | mirror sites