fritz85: PHP & XML & Schleife

Beitrag lesen

Hi Thomas,

danke vielvielmal...

Aber DOMXPath ist auch nicht so kompliziert:

<?php
  $doc = new DOMDocument();

// *****
  $doc->preserveWhiteSpace = false;

$doc->load( 'books.xml' );

// *****
$xpath = new DOMXPath($doc);

$query = '//books/book[(position() > $VON) and (position() <= $BIS)]';

$books= $xpath->query($query);

foreach ($books as $book) {
    // was auch immer hier z.B.
   echo $book->firstChild->nodeValue;
}
  ?>


>   
> $VON und $BIS kannst du ggf. ja dann per URL-Parameter setzen.  
> ($VON darf aber nicht 0 sein, da es in XPath keine "position() = 0" gibt.  
>   
> <http://www.php.net/manual/en/domxpath.query.php>  
>   
  
  
Hab gerade das draus gemacht:  
  
~~~php
  
$doc = new DOMDocument();  
$doc->preserveWhiteSpace = false;  
$doc->load( 'xml.xml' );  
$xpath = new DOMXPath($doc);  
  
$query = "//xmlphp/xmlphp[(position() > 1) and (position() <= 5)]";  
$books = $xpath->query($query);  
foreach ($books as $book)  
{  
 // was auch immer hier z.B.  
 echo $book->text->nodeValue;  
}  

Jedoch kommt nichts...... beim Query muss ich nachhacken..

  
<?xml version="1.0" encoding="ISO-8859-1"?>  
<xmlphp date="29.09.2008, 16:42:08">  
 <xmlphp id="7942">  
  <id>7942</id>  
  <text>Test-text</text>  
  <show_name>Test_showname</show_name>  
  <bild>2342.jpg</bild>  
 </xmlphp>  
</xmlphp>  

So sieht mein XML aus.