Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [XML][PHP] Wyciągniecie dany z konkretnego wiersza
Rafee
post 1.03.2011, 11:42:38
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 2.11.2008

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


Witam,

Jakim najlepszym sposobem będzie wyciągniecie danych z XML a dokładnie z konkretnego wiersza??


Mój plik XML wygląda tak...
  1. <?php
  2. require_once "../maincore.php";
  3.  
  4. if ($settings['hide_userprofiles'] && !iMEMBER) { redirect(BASEDIR."login.php"); }
  5.  
  6. if (isset($_GET['url']) && isnum($_GET['url'])) {
  7. $result = dbquery("SELECT * FROM ".$db_prefix."lonsters WHERE lonsters_id='".$_GET['url']."' LIMIT 1");
  8. }
  9. if (dbrows($result)) { $video_data = dbarray($result); } else { redirect("index.php"); }
  10. header ("Content-Type:text/xml");
  11. ?>
  12. $url = $linkers_data['lonsters_url'];
  13. echo "<xml version=\"1.0\" encoding=\"utf-8\">";
  14. echo "<channel>";
  15. echo "<link>http://www.youtube.com/v/$url</link>";
  16. echo "</channel>";
  17. echo "</xml>";
  18. ?>


I przykładowo link do XML wygląda tak:
Adres: http://www.yousite.pl/movie/y.php?url=11


Zastosowałem do wyciągnięcia taką funkcje:
  1. <?php
  2. $reader = new XMLReader();
  3. $file = "http://www.yousite.pl/movie/y.php?url=11";
  4. $reader->open($file);
  5.  
  6. $count=0;
  7.  
  8. while($reader->read())
  9. {
  10. if($reader->nodeType == XMLReader::ELEMENT)
  11. {
  12. $name = $reader->name;
  13.  
  14. if ($reader->name == 'link')
  15. {
  16. $notes[$count] = array();
  17. }
  18. }
  19.  
  20. if($reader->nodeType == XMLReader::TEXT || $reader->nodeType == XMLReader::CDATA)
  21. {
  22. $notes[$count][$name] = trim($reader->value);
  23. }
  24.  
  25. if($reader->nodeType == XMLReader::END_ELEMENT)
  26. {
  27. if ($reader->name == 'link')
  28. {
  29. $count++;
  30. }
  31. }
  32. }
  33.  
  34. print_r($notes);
  35. ?>


Tylko nie chce aby mi wyświetlało całe drzewo lecz konkretny atrybut, w tym wypadku zawartość węzła <link>

Ten post edytował Rafee 1.03.2011, 12:17:04
Go to the top of the page
+Quote Post
SATIO
post 26.03.2011, 00:45:44
Post #2





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 5.12.2010
Skąd: Gdańsk

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


najszybszym jest xpath na klasie simplexml...


--------------------
Sapletta.pl - Programista PHP, Gdańsk
Go to the top of the page
+Quote Post

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: 10.06.2024 - 07:26