ik heb een xml document
test.xml
ik heb nu de volgende php code (test.php)
hij geeft nu netjes de output maar hij geeft alle output ik wil alleen een aantal outputs in verschillende variabalen zetten (of in een array) zoals prijs zodat ik hier later mee kan rekenen
weet iemand een oplossing?
test.xml
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| <?xml version="1.0" encoding="ISO8859-1" ?> <AANBIEDINGEN> <AANBIEDING> <NAAM>Kb</NAAM> <OMSCHRIJVING>Ook deze sokken worden veel gebruikt voor het dragen in skates. Ze zijn een stuk dunner maar ook erg warm.</OMSCHRIJVING> <FOTO>20.JPG</FOTO> <PRIJS>14,99</PRIJS> </AANBIEDING> <AANBIEDING> <NAAM>Gsus</NAAM> <OMSCHRIJVING>Rokje met tijgerprint en een licht-rose riempje.</OMSCHRIJVING> <FOTO>12.JPG</FOTO> <PRIJS>179,95</PRIJS> </AANBIEDING> </AANBIEDINGEN> |
ik heb nu de volgende php code (test.php)
PHP:
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
| <?php $file = "test.xml"; $map_array = array( "BOLD" => "B", "EMPHASIS" => "I", "LITERAL" => "TT" ); function startElement($parser, $name, $attrs) { global $map_array; if ($htmltag = $map_array[$name]) { print "<$htmltag>"; } } function endElement($parser, $name) { global $map_array; if ($htmltag = $map_array[$name]) { print "</$htmltag>"; } } function characterData($parser, $data) { print $data; print "<br>"; } $xml_parser = xml_parser_create(); characterData(city, $data); // use case-folding so we are sure to find the tag in $map_array xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); ?> |
hij geeft nu netjes de output maar hij geeft alle output ik wil alleen een aantal outputs in verschillende variabalen zetten (of in een array) zoals prijs zodat ik hier later mee kan rekenen
weet iemand een oplossing?