Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

DOMDocument->save()

(no version information, might be only in CVS)

DOMDocument->save() --  Dumps the internal XML tree back into a file

Описание

class DOMDocument {

mixed save ( string filename [, integer options] )

}

Creates an XML document from the DOM representation. This function is usually called after building a new dom document from scratch as in the example below.

Список параметров

filename

The path to the saved XML document.

options

Additional Options. Currently only LIBXML_NOEMPTYTAG is supported.

Возвращаемые значения

Returns the number of bytes written or FALSE if an error occurred.

Список изменений

ВерсияОписание
5.1.0 Added the options parameter

Примеры

Пример 1. Saving a DOM tree into a file

<?php

$doc
= new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;

$root = $doc->createElement('book');
$root = $doc->appendChild($root);

$title = $doc->createElement('title');
$title = $root->appendChild($title);

$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);

echo
'Wrote: ' . $doc->save("/tmp/test.xml") . ' bytes'; // Wrote: 72 bytes

?>



add a note add a note User Contributed Notes
DOMDocument->save()
jon at mysql dot com
02-Nov-2007 03:38
If you're working with an existing XML file that contains an entity definition with an external reference like this one:

[
  <!ENTITY % all.entities SYSTEM "all-entities.ent">
  %all.entities;
]>

Be warned that DOMDocument->save() will expand this to include all definitions in all referenced entities file(s) when it writes the file. In other words, the same section of your saved file would now look something like this:

<!ENTITY % all.entities SYSTEM "all-entities.ent">
<!--
  This file names all the entity files needed by .xml files in the
  current directory.  All ENTITY declarations should be given
  first, followed by references to the those entities.
--><!ENTITY % fixedchars.entities SYSTEM "../common/fixedchars.ent">
<!ENTITY % urls.entities SYSTEM "../refman-common/urls.ent">
<!ENTITY % phrases.entities SYSTEM "../common/phrases.ent">
<!ENTITY % ndb.entities SYSTEM "ndb.en.ent">
<!ENTITY minus "&#x2013;"><!-- 2013 is actually Unicode for ndash -->
<!ENTITY Oslash "&#216;">
<!ENTITY macr "&#175;">
<!ENTITY auml "&#228;">
[etc.]

I've not found a way to keep this from occurring.
siegparr at NOSPAM dot web dot de
07-Jul-2006 08:00
The XML parser converts the text of an XML document into UTF-8, even if you have set the character encoding of the XML, for example as a second parameter of the DOMDocument constructor. After parsing the XML with the load() command all its texts have been converted to UTF-8.

In case you append text nodes with special characters (e. g. Umlaut) to your XML document you should therefore use utf8_encode() with your text to convert it into UTF-8 before you append the text to the document. Otherwise you will get an error message like "output conversion failed due to conv error" at the save() command. See example below:

<?php
// Text to insert into XML below
$txt = "a text with special characters like '
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571