PHP Doku:: Schreibt den internen XML-Baum in eine Zeichenkette - function.domdocument-dump-mem.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzXML-ManipulationDOM-XMLDOM-XML-FunktionenDomDocument->dump_mem

Ein Service von Reinhard Neidl - Webprogrammierung.

DOM-XML-Funktionen

<<DomDocument->dump_file

DomDocument->get_element_by_id>>

DomDocument->dump_mem

(PHP 4 >= 4.1.0)

DomDocument->dump_mem Schreibt den internen XML-Baum in eine Zeichenkette

Beschreibung

string DomDocument->dump_mem ([ bool $format [, string $encoding ]] )

Generiert ein XML-Dokument aus der DOM-Repräsentation. Diese Funktion wird normalerweise aufgerufen, nachdem ein neues DOM-Dokument generiert wurde. Der Parameter format gibt an, ob die Ausgabe sauber formatiert erfolgen soll.

Beispiel #1 Generiere einen HTML-Header

<?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("Das ist der Titel");
$text $title->append_child($text);
echo 
"<PRE>";
echo 
htmlentities($doc->dump_mem(true));
echo 
"</PRE>";
?>

Hinweis:

Der erste Parameter wurde in PHP 4.3.0 hinzugefügt.

Siehe auch domdocument_dump_file() und domdocument_html_dump_mem().


4 BenutzerBeiträge:
- Beiträge aktualisieren...
jonathan at fluent dot ltd dot uk
1.12.2003 1: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
27.09.2003 7: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.10.2002 23: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.08.2002 23: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"?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)