Be careful and dont write attributes after writing text() or any content into xml element, for example
<?php
xml->startelement("div");
xml->text("my text in div");
xml->writeattribute("id",1); // wont write because after adding text
xml->endelement();
?>
XMLWriter::writeAttribute
xmlwriter_write_attribute
(PHP 5 >= 5.1.2, PECL xmlwriter >= 0.1.0)
XMLWriter::writeAttribute -- xmlwriter_write_attribute — 属性全体を書き込む
説明
オブジェクト指向型
bool XMLWriter::writeAttribute
( string
$name
, string $value
)手続き型
bool xmlwriter_write_attribute
( resource
$xmlwriter
, string $name
, string $value
)属性全体を書き込みます。
パラメータ
-
xmlwriter -
手続き型のコールでのみ使用します。 変更される XMLWriter resource です。 このリソースは、xmlwriter_open_uri() あるいは xmlwriter_open_memory() のコールによって取得したものです。
-
name -
属性の名前。
-
value -
属性の値。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
参考
- XMLWriter::writeAttributeNS() - 名前空間つき属性全体を書き込む
- XMLWriter::startAttribute() - 属性を開始する
- XMLWriter::startAttributeNS() - 名前空間つきの属性を開始する
- XMLWriter::endAttribute() - 属性を終了する
Maxim at inbox dot ru
12-Feb-2012 01:01
Jason Hughes
15-Apr-2011 01:37
If you intermix writing sub-elements and attributes, any attributes that are written after the first sub-element are ignored/discarded:
<?php
$xml->startElement('element');
$xml->writeAttribute('attr1', 0);
$xml->writeElement('subelem', 0);
$xml->writeAttribute('attr2', 0);
$xml->endElement();
?>
Outputs:
<element attr1=0>
<subelem>0</subelem>
</element>
This is stupid, but the way it works as of PHP 5.2.4.
