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: Wed, 10 Jun 2009 17:46:58 +0200
Bernhard zwischenbrugger schrieb:
Hi
Try
"textContent" or "nodeValue".
Danke, Bernhard! (Reply off-list.)
Both suggestions work, they're just undocumented.
Here's the modified program:
<?php
$dom = new DOMDocument;
$dom->load( $argv[1]);
$xpath = new DOMXPath( $dom);
$nodelist = $xpath->query( '/files/file/*/text()');
$files = array();
if ( $nodelist ) {
for ( $i = 0; $i < $nodelist->length; ) {
$name = $nodelist->item($i)->textContent; $i++; # works
$size = $nodelist->item($i)->nodeValue; $i++; # also works
$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]