PHP: DOMDocument->load() - Manual

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

search for in the

DOMDocument->loadHTML() DOMDocument->importNode()

Last updated: Sat, 27 Jan 2007

view this page in

# DOMDocument->load()

(no version information, might be only in CVS)

DOMDocument->load() -- Load XML from a file

## Описание

class DOMDocument {
mixed load ( string filename [, int options] )
}

Loads an XML document from a file.

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

`filename`

  The path to the XML document.

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

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки. If called statically, returns a DOMDocument.

## Примеры

Пример 1. Creating a Document

`<?php $doc = new DOMDocument(); $doc->load('book.xml'); echo $doc->saveXML(); ?>`

## Смотрите также

DOMDocument->loadXML()
DOMDocument->save()
DOMDocument->saveXML()

add a note User Contributed Notes
DOMDocument->load()
BadGuy [at] BadGuy [dot] nl
18-Jan-2007 08:50
`Note that this method uses the local file system before doing anything remote. The 'disadvantage' would be that if you would do the following:
<?php
$xml = new DOMDocument;
$xml->load("xmlsource/news.php");
?>
This would not make the method read the actual output of the news.php file --presumably valid xml data--, but the file contents --obviously this would be php code. So this will return an error saying news.php is missing the xml declaration and maybe the xml start-tag
What would work is the following:
<?php
$xml = new DOMDocument;
$xml->load("http://my.beautiful-website.com/xmlsource/news.php");
?>
This will force a http request to be used to get this file instead of just locally reading it and the file just returning code`
daevid at daevid dot com
18-Oct-2005 05:08
`Suppose you wanted to dynamically load an array from an .XSD file. This method is your guy. just remember to use the actual xs: portion in xpaths and such.
All the other "load" methods will error out.
<?php
$attributes = array();
$xsdstring = "/htdocs/api/xsd/common.xsd";
$XSDDOC = new DOMDocument();
$XSDDOC->preserveWhiteSpace = false;
if ($XSDDOC->load($xsdstring))
{
$xsdpath = new DOMXPath($XSDDOC);
$attributeNodes =
$xsdpath->
query('//xs:simpleType[@name="attributeType"]')
->item(0);
foreach ($attributeNodes->childNodes as $attr)
{
$attributes[ $attr->getAttribute('value') ] = $attr->getAttribute('name');
}
unset($xsdpath);
}
print_r($attributes);
?>`
add a note
DOMDocument->loadHTML() DOMDocument->importNode()

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST