A use exemple of this method :
Usefull for generating an XML linked with a XSLT !
<?php
// "Create" the document.
$xml = new DOMDocument( "1.0", "ISO-8859-15" );
//to have indented output, not just a line
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
// ------------- Interresting part here ------------
//creating an xslt adding processing line
$xslt = $xml->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="base.xsl"');
//adding it to the xml
$xml->appendChild($xslt);
// ----------- / Interresting part here -------------
//adding some elements
$root = $xml->createElement("list");
$node = $xml->createElement("contact", "John Doe");
$root-> appendChild($node);
$xml-> appendChild($root);
//creating the file
$xml-> save("output.xml");
?>
output.xml :
<?xml version="1.0" encoding="ISO-8859-15"?>
<?xml-stylesheet type="text/xsl" href="base.xsl"?> //the line has been created successfully
<list>
<contact>John Doe</contact>
</list>
DOMDocument::createProcessingInstruction
(PHP 5)
DOMDocument::createProcessingInstruction — Crea un nuevo nodo PI
Descripción
DOMProcessingInstruction DOMDocument::createProcessingInstruction
( string
$target
[, string $data
] )Esta función crea una nueva instancia de la clase DOMProcessingInstruction. Este nodo no se mostrará en el documento a no ser que sea insertado con (p.e.j.) DOMNode::appendChild().
Parámetros
-
target -
El objetivo de la instrucción de procesamiento.
-
data -
El contenido de la instrucción de procesamiento.
Valores devueltos
El nuevo DOMProcessingInstruction o FALSE si ha ocurrido un error.
Errores/Excepciones
-
DOM_INVALID_CHARACTER_ERR -
Lanzado si
targetcontiene un carácter inválido.
Ver también
- DOMNode::appendChild() - Añade un nuevo hijo al final de los hijos
- DOMDocument::createAttribute() - Crear nuevo attribute
- DOMDocument::createAttributeNS() - Crea un nuevo nodo atributo con un namespace asociado.
- DOMDocument::createCDATASection() - Crea un nuevo nodo cdata
- DOMDocument::createComment() - Crea un nuevo nodo de comentario
- DOMDocument::createDocumentFragment() - Crea un nuevo fragmento de documento
- DOMDocument::createElement() - Crea un nuevo nodo elemento
- DOMDocument::createElementNS() - Crea un nuevo nodo elemento con el nombre de espacio asociado
- DOMDocument::createEntityReference() - Create new entity reference node
- DOMDocument::createTextNode() - Crea un nuevo nodo de texto
romain at supinfo dot com ¶
4 years ago
