PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DomDocument->get_element_by_id> <DomDocument->dump_file
Last updated: Fri, 18 Jul 2008

view this page in

DomDocument->dump_mem

(No version information available, might be only in CVS)

DomDocument->dump_mem — Scarica in una stringa la struttura XML interna

Descrizione

string DomDocument->dump_mem ([ bool $formato [, string $codifica ]] )
Avviso

Questa funzione è SPERIMENTALE. Ovvero, il comportamento di questa funzione, il nome di questa funzione, in definitiva tutto ciò che è documentato qui può cambiare nei futuri rilasci del PHP senza preavviso. Siete avvisati, l'uso di questa funzione è a vostro rischio.

La funzione crea un docuemnto XML dalla rappresentazione DOM. Solitamente si richiama questa funzione dopo avere creato un nuovo documento DOM da zero, come nell'esempio seguente. Il parametro formato specifica se l'output debba essere ben formattato o meno.

Example #1 Creazione dell'intestazione di un documento HTML

<?php
$doc 
domxml_new_doc("1.0");
$root $doc->create_element("HTML");
$root $doc->append_child($root);
$head $doc->create_element("HEAD");
$head $root->append_child($head);
$title $doc->create_element("TITLE");
$title $head->append_child($title);
$text $doc->create_text_node("This is the title");
$text $title->append_child($text);
echo 
"<PRE>";
echo 
htmlentities($doc->dump_mem(true));
echo 
"</PRE>";
?>

Nota: Il primo parametro è stato inserito nella versione 4.3.0 di PHP.

Vedere anche domdocument_dump_file() e domdocument_html_dump_mem().



DomDocument->get_element_by_id> <DomDocument->dump_file
Last updated: Fri, 18 Jul 2008
 
add a note add a note User Contributed Notes
DomDocument->dump_mem
jonathan at fluent dot ltd dot uk
30-Nov-2003 04:11
It seems that if you use $xslt->dump_mem(TRUE) IE: breaks and formats all the HTML Badly. Perhaps its a problem with CR's...
ross at dev-null dot accretivetg dot com
26-Sep-2003 10:11
Given the missing description of the encoding parameter, I had hoped it would automatically encode the document if I set the encoding type; this is not the case.

At least in PHP v4.3.3, it seems that setting the encoding type does NOTHING other than set the name displayed in the string:

<?xml version="1.0" encoding="UTF-8"?>

Thus if you want your values to be encoded, you need to manually encode them when you create your DOM object.  E.g. assume you have a simple setup like this:

<?php

  $text
= '¡Spanish exclamation!' ;

 
$xml = domxml_new_doc( '1.0' );
 
$node = $xml->create_element( 'example' );
 
$cdata = $xml->create_cdata_section( $text );
 
$node->append_child( $cdata );
 
$xml->append_child( $node );

  echo
$xml->dump_mem( true, 'UTF-8' ) ;

 
?>

This will output the following:

<?xml version="1.0" encoding="UTF-8"?>
<example>
<![CDATA[¡Spanish exclamation!]]>
</example>

However, that is not what was intended, as the exclamation is not UTF-8-encoded.  To make $text be encoded correctly, you have to explicitly do so, as in:

<?php

  $cdata
= $xml->create_cdata_section( utf8_encode( $text ) );

 
?>

This results in the output being correctly UTF-8-encoded, as follows:

<![CDATA[¡Spanish exclamation!]]>

Apparently MSIE's MSXML2.DOMDocument ActiveX control requires UTF-8 encoding for special characters, and it will invalidate the entire document if those chars are not appropriately encoded, so beware.
amaslov at pegasus dot rutgers dot edu
23-Oct-2002 02:29
<pre>
for xml file that goes like this:
<item>
<name>foo</name>
<desc>bar</desc>
</item>

Format ID's influence output in this manner:
case 0 :{
<item><name>foo</name><desc>bar</desc></item>
}
case 1 :{
<item>
    <name>foo</name>
    <desc>bar</desc>
</item>
}
case 2:{
<item>
    <name>
foo
    </name>
    <desc>
bar
    </desc>
</item>

If you use PHP SAX(Expat) XML engine, you should always stick to format "0". It reads any empty spaces as XML data.
</pre>
bruno dot rodrigues at litux dot org
15-Aug-2002 02:32
string dump_mem(int format, string encoding);

format=0,1 = <tag>text</tag>
format=2 =
<tag>
  text
</tag>

encoding set's the encoding attribute in line
<?xml version="1.0" encoding="iso-8859-1"?>

DomDocument->get_element_by_id> <DomDocument->dump_file
Last updated: Fri, 18 Jul 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites