Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [xml] najszybszy parser xml'a
grzegorz_g
post
Post #1





Grupa: Zarejestrowani
Postów: 259
Pomógł: 0
Dołączył: 26.10.2004

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


poszukuje najszybszego parsera xml do php, obecnie używam funkcji php SimpleXML
ale mam wrażenie że są szybsze rozwiązania, prawda questionmark.gif

czekam na Wasze propozycje

Ten post edytował grzegorz_g 16.07.2008, 18:22:38


--------------------
www.wettradar.com
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
flashion
post
Post #2





Grupa: Zarejestrowani
Postów: 53
Pomógł: 1
Dołączył: 4.11.2007

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


ja używam DOM XML. jestem bardzo zadowolony smile.gif
Go to the top of the page
+Quote Post
mike
post
Post #3





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


Parsery dzielą się na dwie grupy:
1. Obiektowe, czyli takie, które tworzą drzewo obiektów z XMLa;
2. Strumieniowe, czyli takie, które parsują dokument jak leci. Jak strumień.

Do 1. Zaliczamy DOM XML, DOM, SimpleXml, ... są to parsery wolne już z samej definicji.
Do 2. zaliczamy XMLReader i to jest najszybszy parser XML dla PHP.

~flashion a parsowałeś kiedyś dokument o średniej złożoności i o wadze powyżej 50MB?
Go to the top of the page
+Quote Post
grzegorz_g
post
Post #4





Grupa: Zarejestrowani
Postów: 259
Pomógł: 0
Dołączył: 26.10.2004

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


dla ekspertów xml'a to pytanie banalne, mi jednak sprawia sporo kłopotów.

Wybrałem : XMLReader, poczytałem mauala jednak nie mogę zastosować tej klasy do mojego przykładu.

próbuje użyć przykładów z manuala:

  1. <?php
  2. /*
  3. Read XML structure to associative array
  4. --
  5. Using:
  6. $xml = new XMLReader();
  7. $xml->open([XML file]);
  8. $assoc = xml2assoc($xml);
  9. $xml->close();
  10. */
  11. function xml2assoc($xml) {
  12. $assoc = null;
  13. while($xml->read()){
  14. switch ($xml->nodeType) {
  15. case XMLReader::END_ELEMENT: return $assoc;
  16. case XMLReader::ELEMENT:
  17. $assoc[$xml->name][] = array('value' => $xml->isEmptyElement ? '' : xml2assoc($xml));
  18. if($xml->hasAttributes){
  19. $el =& $assoc[$xml->name][count($assoc[$xml->name]) - 1];
  20. while($xml->moveToNextAttribute()) $el['attributes'][$xml->name] = $xml->value;
  21. }
  22. break;
  23. case XMLReader::TEXT:
  24. case XMLReader::CDATA: $assoc .= $xml->value;
  25. }
  26. }
  27. return $assoc;
  28. }
  29. ?>
  30.  
  31.  
  32. ale nawet nie wiem gdzie mam wstawić plik xml który zakupilem, to adres pliku : <a href=\"http://www.timeandscore.com/xml/?username=\" target=\"_blank\">http://www.timeandscore.com/xml/?username=</a>[...user...]&password=[...pass...]


--------------------
www.wettradar.com
Go to the top of the page
+Quote Post
Sajrox
post
Post #5





Grupa: Zarejestrowani
Postów: 254
Pomógł: 7
Dołączył: 9.10.2007
Skąd: Poznań

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


Dziwny masz ten plik :/

  1. <?php
  2. // Twoj plik xml
  3. $plikXML = '';
  4.  
  5. $xml = new XMLReader();
  6. $xml->open($plikXML);
  7. $assoc = xml2assoc($xml);
  8. $xml->close();
  9. ?>



Ja uzywam czegoś takiego:
  1. <?php
  2. $reader = new XMLReader();
  3.  
  4. $reader->open('jakis_plik.xml');
  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 == 'offer')
  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 == 'offer')
  28.        {
  29.              $count++;
  30.        }
  31.    }
  32. }
  33.  
  34. // Tutaj wyswietlam otrzymana tablicę
  35. echo '<pre>';
  36. print_r($notes);
  37. ?>


Przykłądowy plik XML do tego

  1. <?xml version="1.0" encoding="ISO-8859-2"?>
  2. <!DOCTYPE nokaut SYSTEM "http://www.nokaut.pl/integracja/nokaut.dtd">
  3. <nokaut>
  4. <offers>
  5.  
  6.    <offer>
  7.    <id>1</id>
  8.    <name>Nazwa czegos</name>
  9.    <description>Jakis opis</description>
  10.    </offer>
  11.  
  12.    <offer>
  13.    <id>2</id>
  14.    <name>Nazwa czegos 2</name>
  15.    <description>Jakis opis 2</description>
  16.    </offer>
  17.    
  18. </offers>
  19. </nokaut>
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 Aktualny czas: 20.08.2025 - 13:26