Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]problem z plikiem xml
sweter
post 23.09.2009, 20:53:40
Post #1





Grupa: Zarejestrowani
Postów: 623
Pomógł: 11
Dołączył: 1.01.2009
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Witam, mam taki plik XML:

Kod
<?xml version="1.0" encoding="utf-8"?>
<notes>
    <note>
        <date id="123">2007-06-24</date>
        <heading>qwerty</heading>
        <body>asd</body>
    </note>
    <note>
        <date id="456">2008-01-04</date>
        <heading>qwerty2</heading>
        <body>asd2</body>
    </note>
</notes>


i taki plik PHP, który zajmuje się przetwarzaniem pliku:

  1.  
  2. $reader = new XMLReader();
  3. $reader->open('oferty3.xml');
  4.  
  5.  
  6. while($reader->read()) {
  7. if($reader->nodeType == XMLReader::ELEMENT){
  8. $name = $reader->name;
  9. }
  10.  
  11. if($reader->nodeType == XMLReader::ELEMENT AND $reader->nodeType=="note"){
  12.   $name = $reader->name;
  13. }
  14.  
  15. if($reader->nodeType == XMLReader::TEXT){
  16. if($name=="date"){
  17. echo "<li>".$name."(".$reader->getAttribute('id').") ".$reader->value."</li>";
  18. }else{
  19. echo "<li>".$name." ".$reader->value."</li>";
  20. }
  21. }
  22.  
  23.  
  24. }
  25.  
  26.  


W wyniku otrzymuję coś takiego:

Cytat
date() 2007-06-24
heading qwerty
body asd
date() 2008-01-04
heading qwerty2
body asd2


Mój problem polega na tym, że w nawiasach za słówkiem "date" nie wyświetla się wartość id z pliku XML.

Co jest źle?



--------------------
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 09:29