PHP XMLWriter

WBOY
Freigeben: 2024-08-29 13:09:43
Original
203 Leute haben es durchsucht

Der XML-Writer wird zum Erstellen von Dateien oder Datenströmen in PHP verwendet. Wenn Sie XML-Inhalte speichern oder eine Datei generieren möchten, die XML-Daten enthalten kann, sollten Sie sich für den XML-Writer in PHP entscheiden. Der XML-Writer enthält mehrere Methoden zum Umgang mit XML-Inhalten in PHP. Wir können darin auch unsere HTML-Daten hinzufügen. Der XML-Writer bietet verschiedene Methoden, die zum Erstellen von Dokumenten, zum Anfang des Attributs, zum Ende des Attributs usw. verwendet werden können. Im kommenden Abschnitt werden wir näher auf den XML-Writer und seine Methoden eingehen, die für den Umgang mit XML-Inhalten verwendet werden können.

WERBUNG Beliebter Kurs in dieser Kategorie PHP-ENTWICKLER - Spezialisierung | 8-Kurs-Reihe | 3 Probetests

Starten Sie Ihren kostenlosen Softwareentwicklungskurs

Webentwicklung, Programmiersprachen, Softwaretests und andere

Syntax

Als XML-Autor stehen Ihnen so viele Methoden zur Verfügung, mit denen Sie Dokumente, Attribute und viele andere Dinge erstellen können. Aber wir müssen das Objekt des XML Writers erstellen, nachdem wir seine Methoden aufrufen können, um XML-Inhalte zu erstellen. Sehen wir uns die Syntax im Detail an, um sie besser zu verstehen, siehe unten;

$mywriter = new XMLWriter(); $mywriter->anymethod('output');
Nach dem Login kopieren

Wie wir sehen können, erstellen wir in den obigen Syntaxzeilen das XML-Writer-Objekt. Danach können wir jede beliebige Methode aufrufen, um mit XML umzugehen. Im kommenden Abschnitt werden wir ein Übungsbeispiel sehen, um es besser zu verstehen.

Wie funktioniert der XML-Writer in PHP?

Wie wir jetzt wissen, ist der XML-Writer die Klasse, die so viele Methoden bereitstellt, die für den Umgang mit XML verwendet werden können. Auf diese Weise können wir einen Datenstrom oder Dateien generieren, die den XML-Inhalt enthalten. Darin können wir auch unsere HTML-Attribute und Tags haben. In diesem Abschnitt besprechen wir mehr über die verfügbaren Methoden, wie man sie beim Programmieren verwendet und wie sie im Detail mit ihrer Methodensignatur verwendet werden, siehe auch unten;

Methoden

Einige der verfügbaren Methoden werden unten beschrieben;

  • 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');
Nach dem Login kopieren

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(); ?>
Nach dem Login kopieren

Output:

PHP XMLWriter

Conclusion

Grâce à l'utilisation de XMLWriter, nous pouvons créer du contenu XML. Il nous fournit également diverses méthodes dont nous avons déjà parlé. Pour les utiliser, nous avions besoin d'un objet XMLWriter pour les appeler. Nous pouvons créer des commentaires, des attributs et des balises en utilisant ces méthodes.

Das obige ist der detaillierte Inhalt vonPHP XMLWriter. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Verwandte Etiketten:
php
Quelle:php
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!