[php] xml parse

Pagina: 1
Acties:

Onderwerpen


Verwijderd

Topicstarter
Kan iemand mij misschien vertellen waarom de volgende code alleen de eerste <img ... >...</img> parsed en niet de 2e?

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
class xml  {

var $parser;

var $stack = array();

   function xml()
   {
        $this->parser = xml_parser_create();

        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);

        xml_set_object($this->parser, &$this);

        xml_set_element_handler($this->parser, "tag_open", "tag_close");

        xml_set_character_data_handler($this->parser, "cdata");
   }

   function parse($data)
   {
        xml_parse($this->parser, $data, true);

        while (!xml_parse) {

                $this->parse(&$data);
        }
}

   function tag_open($parser, $tag, $attributes)
   {
        if ($tag == 'img') {

                array_push($this->stack, $attributes['src']);
        }
   }

   function cdata($parser, $cdata)
   {

   }

   function tag_close($parser, $tag)
   {

   }

} // end of class xml

        $xml_parser = new xml();

        $xml_parser->parse("[img]'hallo'>beschrijving</img><img[/img]beschrijving</img>");

        foreach ($xml_parser->stack as $value) {

                print($value);
        }
?>

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

code:
23
24
25
xml_parse($this->parser, $data, true);

while (!xml_parse) {
euhmmm... sniegoed :) Kijk eens in de manual naar het voorbeeld wat daar staat, daarmee moet je er wel uit komen, toch?

voici

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Verwijderd

Topicstarter
code:
1
xml_parse($this->parser, $data);


die zou genoeg moeten zijn, aangezien $data alles bevat en er niets uit een bestand wordt gelezen.

maar het is niet genoeg, want hij output nog maar steeds 1 tag :(

Verwijderd

Topicstarter
Mjah hehe

vergeten dat er natuurlijk een document root moet zijn.

foutjeeeeeee...

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

'Junk after document element' ;) Leve het netjes op errors blijven checken, altijd en overal :)

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz