|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
i'm new to parsing XML with PHP
i have the following XML file: <cds> <id>1</id> <Composer>Bach</Composer> <Title>Goldberg Variations</Title> <Performer>Leonhardt</Performer> <Works>Goldberg Variations</Works> <Label>DHM</Label> <n>77149-2-RG</n> <Category>Keyb</Category> <x>1</x> <c>-</c> <Imagenes>bach_goldberg.jpg</Imagenes> </cds> <cds> <id>2</id> <Composer>Berlioz</Composer> <Title>Symphonie Fantastique</Title> <Performer>Norrington - LCP</Performer> <Works>Symphonie Fantastique</Works> <Label>EMI</Label> <n>549541</n> <Category>Orch</Category> <x>1</x> <c>-</c> <Imagenes>berlioz_norrington.jpg</Imagenes> </cds> etc.... i'm using: function startElemHandler($parser, $name, $attribs) { if (strcasecmp($name, "cds") == 0) { echo "<ul>\n"; } if (strcasecmp($name, "Composer") == 0) { $composer=$attribs['']; echo "<li>".$composer."</li>\n"; } } as <composer> doesn't have any attributes, i don't know how to show the text between the <composer> and </composer> tags. from what i've read $attribs is an array where the keys are the name of the attributes names and the values are the attribute values. But, what in the example above where there is no keys? i tried it with an xml where i modified the tags to show: <Composer name='Berlioz'>Berlioz</Composer> and then i used: $composer=$attribs['name']; and it worked...but that's note the right solution. tahnk you very much for your , NN |
|
![]() |
| Outils de la discussion | |
|
|