XMLWriter::startDocument
xmlwriter_start_document
(PHP 5 >= 5.1.2, PECL xmlwriter >= 0.1.0)
XMLWriter::startDocument -- xmlwriter_start_document — Создать тэг документа
Описание
Объектно-ориентированный стиль
bool XMLWriter::startDocument
([ string
$version
= 1.0
[, string $encoding
= NULL
[, string $standalone
]]] )Процедурный стиль
bool xmlwriter_start_document
( resource
$xmlwriter
[, string $version
= 1.0
[, string $encoding
= NULL
[, string $standalone
]]] )Начинает документ.
Список параметров
-
xmlwriter
-
Только для процедурных вызовов. Изменяемый resource XMLWriter. Этот ресурс может быть получен из xmlwriter_open_uri() или xmlwriter_open_memory().
-
version
-
Номер версии документа как часть объявления XML.
-
encoding
-
Кодировка документа как часть объявления XML.
-
standalone
-
yes или no.
Возвращаемые значения
Возвращает TRUE
в случае успешного завершения или FALSE
в случае возникновения ошибки.
- XMLWriter::endAttribute
- XMLWriter::endCData
- XMLWriter::endComment
- XMLWriter::endDocument
- XMLWriter::endDTDAttlist
- XMLWriter::endDTDElement
- XMLWriter::endDTDEntity
- XMLWriter::endDTD
- XMLWriter::endElement
- XMLWriter::endPI
- XMLWriter::flush
- XMLWriter::fullEndElement
- XMLWriter::openMemory
- XMLWriter::openURI
- XMLWriter::outputMemory
- XMLWriter::setIndentString
- XMLWriter::setIndent
- XMLWriter::startAttributeNS
- XMLWriter::startAttribute
- XMLWriter::startCData
- XMLWriter::startComment
- XMLWriter::startDocument
- XMLWriter::startDTDAttlist
- XMLWriter::startDTDElement
- XMLWriter::startDTDEntity
- XMLWriter::startDTD
- XMLWriter::startElementNS
- XMLWriter::startElement
- XMLWriter::startPI
- XMLWriter::text
- XMLWriter::writeAttributeNS
- XMLWriter::writeAttribute
- XMLWriter::writeCData
- XMLWriter::writeComment
- XMLWriter::writeDTDAttlist
- XMLWriter::writeDTDElement
- XMLWriter::writeDTDEntity
- XMLWriter::writeDTD
- XMLWriter::writeElementNS
- XMLWriter::writeElement
- XMLWriter::writePI
- XMLWriter::writeRaw
Коментарии
I was having a very hard time triyng to use:
$writer->startDocument( '1.0' , 'Windows-1252' );
Somehow this caused the generation of an empty xml file, and I could not figure out why.
When all other efforts failed I asked for help to the team that developed the XMLwriter extension, and got a very quick reply as follows:
Quote:
==============================
Windows-1252 support is only available if libxml2 is link with iconv
support (it usually is, but there are exceptions). I know on my Mac, the
built in libxml2 doesnt provide iconv support - they go with some
Unicode hack which doesnt provide it, so I had to build my own. It is
built by default (and your code works) on my linux machines.
It is possible to create the XML without a declaration, which means you
could add it manually, but if you use any characters that are differnt
between UTF-8 and Windows-1252, the encoding would be wrong in the
document, so do not recommend.
==============================
Then light was made on my head: I am using a linux server distribution that by default is still running PHP 4.3. A few months ago I decided to force the upgrade of PHP to the newest version 5.1.6 at that time, and that has brougth me the XMLwriter extension that I am now using. But clearly there are compatibility issues betwen the rest of the server's defaults and PHP 5 wich is probably why it's development team has not upgraded yet.
Let's hope all the remaining environments catch up with this extension. It is in fact most handy.
And in the meantime, I have figured out a (not recomended, obviously) workaroud that works for me:
Instead of using two parameters, I used only the first one:
$writer->startDocument( '1.0" encoding="Windows-1252' );
this will output:
<?xml version="1.0" encoding="Windows-1252"?>
Some errors in generating the XML document are related to the format used to write the PHP file from which the XML is generated.
In Windows environments, be sure to save your documents in ANSI / ASCII and you will avoid many of them.