Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][xml] Problem z xpath w SimpleXML
terabit
post
Post #1





Grupa: Zarejestrowani
Postów: 170
Pomógł: 4
Dołączył: 11.08.2006

Ostrzeżenie: (10%)
X----


Witam,

czy ktoś może mi wytłumaczyć dlaczego w poniższym kodzie wyswietla mi tylko ostatni element title dokumentu XML?
wydaje mi sie ze tablica powinna zawietac wszystkie znalezione elementy title...

bardzo proszę o wyjaśnienie.

  1. <?php
  2.  
  3. $library = new SimpleXMLElement('library.xml', NULL, true);
  4.  
  5.  
  6. $results = $library->xpath('/library/book/title');
  7. foreach ($results as $title);
  8. {
  9. echo $title . "\n";
  10. }
  11.  
  12.  
  13. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
terabit
post
Post #2





Grupa: Zarejestrowani
Postów: 170
Pomógł: 4
Dołączył: 11.08.2006

Ostrzeżenie: (10%)
X----


  1. <?xml version="1.0"?>
  2. <library>
  3. <book isbn="03454">
  4. <title>Gahreheit</title>
  5. <author>B. Bradburg</author>
  6. <publisher>Del Rey</publisher>
  7. </book>
  8. <book isbn="004823">
  9. <title>The Silmarillion</title>
  10. <author>J.R.R. Tolien</author>
  11. <publisher>G. Allen and Unwin</publisher>
  12. </book>
  13. <book isbn="2323">
  14. <title>Mariusz</title>
  15. <author>Ktos</author>
  16. <publisher>Helion</publisher>
  17. </book>
  18. </library>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.12.2025 - 03:14