PHP XMLWriter

WBOY
Lepaskan: 2024-08-29 13:09:43
asal
267 orang telah melayarinya

Penulis XML digunakan untuk mencipta fail atau aliran data dalam PHP. Jika anda ingin menyimpan XML mengandungi atau ingin menjana sebarang fail yang boleh mengandungi data XML maka kita harus pergi untuk penulis XML dalam PHP. Penulis XML mengandungi beberapa kaedah untuk menangani kandungan XML dalam PHP, kami juga boleh menambah data HTML kami di dalamnya. Penulis XML menyediakan pelbagai kaedah yang boleh digunakan untuk membuat dokumen, permulaan atribut, akhir atribut, dan sebagainya. Dalam bahagian yang akan datang, kami akan membincangkan lebih lanjut tentang penulis XML dan kaedahnya yang boleh digunakan untuk menangani kandungan XML.

IKLAN Kursus Popular dalam kategori ini PEMBANGUN PHP - Pengkhususan | 8 Siri Kursus | 3 Ujian Olok-olok

Mulakan Kursus Pembangunan Perisian Percuma Anda

Pembangunan web, bahasa pengaturcaraan, ujian perisian & lain-lain

Sintaks

Memandangkan penulis XML mempunyai begitu banyak kaedah yang tersedia yang boleh digunakan untuk mencipta dokumen, atribut dan banyak lagi perkara. Tetapi kita perlu mencipta objek Penulis XML selepas ini kita boleh memanggil kaedahnya untuk mencipta kandungan XML. Mari lihat sintaksnya secara terperinci untuk memahaminya dengan lebih baik lihat di bawah;

$mywriter = new XMLWriter();
$mywriter->anymethod('output');
Salin selepas log masuk

Dalam baris sintaks di atas seperti yang kita lihat kita sedang mencipta objek XML Writer selepas ini kita boleh memanggil sebarang kaedah untuk menangani XML. Dalam bahagian yang akan datang, kita akan melihat contoh amalan untuk memahaminya dengan lebih baik.

Bagaimanakah penulis XML berfungsi dalam PHP?

Seperti yang kita ketahui sekarang bahawa penulis XML ialah kelas yang menyediakan begitu banyak kaedah yang boleh digunakan untuk menangani XML. Dengan menggunakan ini, kami boleh menjana aliran data atau fail yang mengandungi kandungan XML. Di dalam ini, kami juga boleh mempunyai atribut dan teg HTML kami juga. Dalam bahagian ini kita akan membincangkan lebih banyak kaedah yang tersedia bagaimana untuk menggunakannya semasa pengaturcaraan dan penggunaannya secara terperinci dengan tandatangan kaedah mereka juga lihat di bawah;

Kaedah

Beberapa kaedah yang tersedia diterangkan di bawah;

  • XMLWriter::writeElementNs — This method is used to create the write full namespaced element.
  • XMLWriter::writeElement — This method is used to create the write full element.
  • XMLWriter::writePi — This method is used to create the writes PI
  • XMLWriter::writeRaw — This method is used to create the write raw XML text
  • XMLWriter::startCdata — This method is used to create the CDATA tag
  • XMLWriter::startComment — This method is used to create the comment
  • XMLWriter::startDocument — This method is used to create the document tag
  • XMLWriter::startDtdAttlist — This method is used to create the DTD AttList
  • XMLWriter::startDtdElement — This method is used to create the DTD element
  • XMLWriter::startDtdEntity — This method is used to create the DTD Entity
  • XMLWriter::writeAttribute — This method is used to create the write full attribute
  • XMLWriter::writeCdata — This method is used to create the write full CDATA tag in XMLWriter.
  • XMLWriter::writeComment — This method is used to create the write full comment tag in XMLWriter.
  • XMLWriter::writeDtdAttlist — This method is used to create the write full DTD AttList tag in XMLWriter.
  • XMLWriter::writeDtdElement — This method is used to create the write full DTD element tag in XMLWriter.
  • XMLWriter::writeDtdEntity — This method is used to create the write full DTD Entity.
  • XMLWriter::endAttribute — This method is used to end the attribute after the start.
  • XMLWriter::endCdata — By the use of this we can end the current CDATA in XMLWriter.
  • XMLWriter::endComment — This method is used to create the comment but the end comment.
  • XMLWriter::endDocument — This method is used to end the document but this document would be a current document.
  • XMLWriter::endDtdAttlist — This method is used to end the current DTD AttList (may be attricute list)
  • XMLWriter::endDtdElement — This method is used to end the current DTD element
  • XMLWriter::endDtdEntity — This method is used to end the current DTD Entity
  • XMLWriter::endDtd — this method is used to end the current DTD
  • XMLWriter::endElement — This method ends the current elements of XMLWriter.
  • XMLWriter::endPi — This methd is used to end current PI
  • XMLWriter::flush — This method is used to flush the buffer.
  • XMLWriter::fullEndElement — This method is also used to end the current element.
  • XMLWriter::openMemory — This method is sued to create xmlwriter.
  • XMLWriter::startDtd — This method is used to create the DTD in XMLWriter.
  • XMLWriter::startElementNs — This method is used to create the namespaced element tag in XMLWriter.
  • XMLWriter::startElement — This method is used to create the element tag
  • XMLWriter::startPi — This method is used to create the PI tag in XMLWriter.
  • XMLWriter::text — This method is used to create the write text.
  • XMLWriter::writeAttributeNs — This method is used to create the write full namespaced attribute
  • XMLWriter::openUri — This method is used to create xmlwriter using the specified source uri.
  • XMLWriter::outputMemory — This method is used to return the current buffer
  • XMLWriter::setIndentString — This method is used t set the string for indenting
  • XMLWriter::setIndent — This method is used to toggle the indentation (on/off)
  • XMLWriter::startAttributeNs — This method is used to create the start name spaced attribte.
  • XMLWriter::startAttribute — This method is used to create the start attribute.
  • XMLWriter::writeDtd — This method is used to create the write full DTD.

Let’s take one example to understand it better see below;

  • First, create the XML Writer object.
  • 2) After that we can call any method on the given object. We have already discussed the methods and their work in detail.
  • To create XML document we can call start document method and inside this, we can specify the XML version number and the encoding type which will be the first line available in the output.
  • Below see the sample to begin with XML writer in PHP see below;

e.g. :

$mywriter->startDocument('1.0', 'UTF-8');
Salin selepas log masuk

These are the required parameter that need to pass while dealing with XML writer.

Example of PHP XMLWriter

In this example, we are creating one document. We have two methods from XMLWriter to create the document. First, we have start the document and at the end, we are closing it. Make sure you have the proper setup to run the program otherwise it won’t run.

Example #1

openURI('php://output');
$mywriter->startDocument('1.0', 'UTF-8');
$mywriter->endDocument();
?>
Salin selepas log masuk

Output:

PHP XMLWriter

Kesimpulan

Dengan penggunaan XMLWriter kita boleh mencipta kandungan XML juga ia memberikan kita pelbagai kaedah yang telah kita bincangkan, untuk menggunakannya, kita memerlukan objek XMLWriter untuk memanggilnya. Kita boleh membuat ulasan, atribut, dan teg dengan menggunakan kaedah ini.

Atas ialah kandungan terperinci PHP XMLWriter. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
php
sumber:php
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!