Re: [xml] How to extract text content using the PHP interface?
- From: Michael Ludwig <mlu as-guides com>
- To: "Xml Gnome Org" <xml gnome org>
- Subject: Re: [xml] How to extract text content using the PHP interface?
- Date: Mon, 15 Jun 2009 17:57:32 +0200
Michael Ludwig schrieb:
<?php
$dom = new DOMDocument;
$dom->load( $argv[1]);
$xpath = new DOMXPath( $dom);
$nodelist = $xpath->query( '/files/file/*/text()');
Of course, the XPath should be just '/files/file/*'. I simply forgot
to remove the text() node test. I want the string value here, not
individual text nodes. Both ->nodeValue and ->textContent work fine
for that purpose.
<?php
$dom = new DOMDocument;
$dom->load( $argv[1]);
$xpath = new DOMXPath( $dom);
$nodelist = $xpath->query( '/files/file/*');
$files = array();
if ( $nodelist ) {
for ( $i = 0; $i < $nodelist->length; ) {
$name = $nodelist->item($i++)->textContent; # works fine
$size = $nodelist->item($i++)->nodeValue; # also works fine
$files[] = array( 'name' => $name, 'size' => $size);
}
}
else {
echo "nichts gefunden\n";
}
var_dump( $files);
Michael Ludwig
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]