TD Joel
Mitglied
Hallo zusammen
ich suche nach einer möglichkeit xml-daten in php auszugeben. die erste zeile kann ich auslesen, aber die folgenden will es einfach nicht anzeigen. danke für die Hilfe
Code des php scripts
CODE function startElement($parser, $name, $atts) {
global $html;
// Die XML-Namen werden in Großbuchstaben übergeben.
// Deshalb wandeln wir sie mit strtolower() in Klein-
// buchstaben um.
switch (strtolower($name)) {
case "products":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["products"]."\"></a>";
break;
case "product":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["product"]."\"></a>";
break;
case "name":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["name"]."\"></a>";
break;
case "productUrl":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["productUrl"]."\"></a>";
break;
case "imageUrl":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["imageUrl"]."\"></a>";
break;
case "description":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["description"]."\"></a>";
break;
case "price":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["price"]."\"></a>";
break;
case "currency":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["currency"]."\"></a>";
break;
case "TDProductId":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["TDProductId"]."\"></a>";
break;
case "TDCategoryID":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["TDCategoryID"]."\"></a>";
break;
case "TDCategoryName":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["TDCategoryName"]."\"></a>";
break;
case "merchantCategoryName":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["merchantCategoryName"]."\"></a>";
break;
case "sku":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["sku"]."\"></a>";
break;
case "shortDescription":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["shortDescription"]."\"></a>";
break;
case "promoText":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["promoText"]."\"></a>";
break;
case "previousPrice":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["previousPrice"]."\"></a>";
break;
case "warranty":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["warranty"]."\"></a>";
break;
case "availability":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["availability"]."\"></a>";
break;
case "inStock":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["inStock"]."\"></a>";
break;
case "shippingCost":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["shippingCost"]."\"></a>";
break;
case "deliveryTime":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["deliveryTime"]."\"></a>";
break;
case "weight":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["weight"]."\"></a>";
break;
case "size":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["size"]."\"></a>";
break;
case "brand":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["brand"]."\"></a>";
break;
case "model":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["model"]."\"></a>";
break;
case "ean":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["ean"]."\"></a>";
break;
case "upc":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["upc"]."\"></a>";
break;
case "isbn":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["isbn"]."\"></a>";
break;
case "condition":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["condition"]."\"></a>";
break;
case "mpn":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["mpn"]."\"></a>";
break;
case "techSpecs":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["techSpecs"]."\"></a>";
break;
case "manufacturer":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["manufacturer"]."\"></a>";
break;
case "programName":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["programName"]."\"></a>";
break;
case "programLogoPath":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["programLogoPath"]."\"></a>";
break;
case "programId":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["programId"]."\"></a>";
break;
default:
// Ein ungültiges Element ist vorgekommen.
$error = "Undefiniertes Element <".$name.">";
die($error . " in Zeile " .
xml_get_current_line_number($parser));
break;
}
}
/**
* Diese Funktion behandelt ein abschließendes Element
* Alle Parameter werden automatisch vom Parser übergeben
*
* @param parser Object Parserobjekt
* @param name string Name des schließenden Elements
*/
function endElement($parser, $name) {
global $html;
switch (strtolower($name)) {
case "ref":
// Den HTML-Link schließen:
$html .= "</a>";
break;
}
}
/**
* Diese Funktion behandelt normalen Text
* Alle Parameter werden automatisch vom Parser übergeben
*
* @param parser Object Parserobjekt
* @param text string Der Text
*/
function cdata($parser, $text) {
global $html;
// Der normale Text wird einfach an $html angehängt:
$html .= $text;
}
// Die XML-Datei wird in die Variable $xmlFile eingelesen
$xmlFile = implode("", file("xml/xml_exlibris.xml"));
// Der Parser wird erstellt
$parser = xml_parser_create();
// Setzen der Handler
xml_set_element_handler($parser,"startElement","endElement");
// Setzen des CDATA-Handlers
xml_set_character_data_handler($parser, "cdata");
// Parsen
xml_parse($parser, $xmlFile);
// Gibt alle verbrauchten Ressourcen wieder frei.
xml_parser_free($parser);
// Ausgabe der globalen Variable $html.
print $html;
Code des XML Files
CODE <?xml version="1.0" encoding="ISO-8859-1"?>
<products>
<product>
<name />Jonathan Nasaw - Der Kuss der Schlange</name>
<productUrl />http://pdt.tradedoubler.com/click?a(1595012)p(48665)prod(550284375)ttid(5)</productUrl>
<imageUrl />http://www.exlibris.ch/images_products/139-0147-6.jpg</imageUrl>
<description />Keine Beschreibung vorhanden</description>
<price />14.35</price>
<currency />CHF</currency>
<TDProductId>550284375</TDProductId>
<TDCategoryID>4</TDCategoryID>
<TDCategoryName>Books</TDCategoryName>
<merchantCategoryName/>
<sku/>
<shortDescription/>
<promoText/>
<previousPrice/>
<warranty/>
<availability/>
<inStock/>
<shippingCost/>
<deliveryTime/>
<weight/>
<size/>
<brand/>
<model/>
<ean/>
<upc/>
<isbn/>
<condition/>
<mpn/>
<techSpecs/>
<manufacturer/>
<programName>Ex Libris AG</programName>
<programLogoPath>http://hst.tradedoubler.com/file/26320/logo/100/ex_libris_logo_100x50.gif</programLogoPath>
<programId>48665</programId>
<fields/>
</product>
</products>
ich suche nach einer möglichkeit xml-daten in php auszugeben. die erste zeile kann ich auslesen, aber die folgenden will es einfach nicht anzeigen. danke für die Hilfe
Code des php scripts
CODE function startElement($parser, $name, $atts) {
global $html;
// Die XML-Namen werden in Großbuchstaben übergeben.
// Deshalb wandeln wir sie mit strtolower() in Klein-
// buchstaben um.
switch (strtolower($name)) {
case "products":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["products"]."\"></a>";
break;
case "product":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["product"]."\"></a>";
break;
case "name":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["name"]."\"></a>";
break;
case "productUrl":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["productUrl"]."\"></a>";
break;
case "imageUrl":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["imageUrl"]."\"></a>";
break;
case "description":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["description"]."\"></a>";
break;
case "price":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["price"]."\"></a>";
break;
case "currency":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["currency"]."\"></a>";
break;
case "TDProductId":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["TDProductId"]."\"></a>";
break;
case "TDCategoryID":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["TDCategoryID"]."\"></a>";
break;
case "TDCategoryName":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["TDCategoryName"]."\"></a>";
break;
case "merchantCategoryName":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["merchantCategoryName"]."\"></a>";
break;
case "sku":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["sku"]."\"></a>";
break;
case "shortDescription":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["shortDescription"]."\"></a>";
break;
case "promoText":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["promoText"]."\"></a>";
break;
case "previousPrice":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["previousPrice"]."\"></a>";
break;
case "warranty":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["warranty"]."\"></a>";
break;
case "availability":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["availability"]."\"></a>";
break;
case "inStock":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["inStock"]."\"></a>";
break;
case "shippingCost":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["shippingCost"]."\"></a>";
break;
case "deliveryTime":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["deliveryTime"]."\"></a>";
break;
case "weight":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["weight"]."\"></a>";
break;
case "size":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["size"]."\"></a>";
break;
case "brand":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["brand"]."\"></a>";
break;
case "model":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["model"]."\"></a>";
break;
case "ean":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["ean"]."\"></a>";
break;
case "upc":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["upc"]."\"></a>";
break;
case "isbn":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["isbn"]."\"></a>";
break;
case "condition":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["condition"]."\"></a>";
break;
case "mpn":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["mpn"]."\"></a>";
break;
case "techSpecs":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["techSpecs"]."\"></a>";
break;
case "manufacturer":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["manufacturer"]."\"></a>";
break;
case "programName":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["programName"]."\"></a>";
break;
case "programLogoPath":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["programLogoPath"]."\"></a>";
break;
case "programId":
// Einen HTML-Anker erzeugen:
$html .= "<a name=\"".$atts["programId"]."\"></a>";
break;
default:
// Ein ungültiges Element ist vorgekommen.
$error = "Undefiniertes Element <".$name.">";
die($error . " in Zeile " .
xml_get_current_line_number($parser));
break;
}
}
/**
* Diese Funktion behandelt ein abschließendes Element
* Alle Parameter werden automatisch vom Parser übergeben
*
* @param parser Object Parserobjekt
* @param name string Name des schließenden Elements
*/
function endElement($parser, $name) {
global $html;
switch (strtolower($name)) {
case "ref":
// Den HTML-Link schließen:
$html .= "</a>";
break;
}
}
/**
* Diese Funktion behandelt normalen Text
* Alle Parameter werden automatisch vom Parser übergeben
*
* @param parser Object Parserobjekt
* @param text string Der Text
*/
function cdata($parser, $text) {
global $html;
// Der normale Text wird einfach an $html angehängt:
$html .= $text;
}
// Die XML-Datei wird in die Variable $xmlFile eingelesen
$xmlFile = implode("", file("xml/xml_exlibris.xml"));
// Der Parser wird erstellt
$parser = xml_parser_create();
// Setzen der Handler
xml_set_element_handler($parser,"startElement","endElement");
// Setzen des CDATA-Handlers
xml_set_character_data_handler($parser, "cdata");
// Parsen
xml_parse($parser, $xmlFile);
// Gibt alle verbrauchten Ressourcen wieder frei.
xml_parser_free($parser);
// Ausgabe der globalen Variable $html.
print $html;
Code des XML Files
CODE <?xml version="1.0" encoding="ISO-8859-1"?>
<products>
<product>
<name />Jonathan Nasaw - Der Kuss der Schlange</name>
<productUrl />http://pdt.tradedoubler.com/click?a(1595012)p(48665)prod(550284375)ttid(5)</productUrl>
<imageUrl />http://www.exlibris.ch/images_products/139-0147-6.jpg</imageUrl>
<description />Keine Beschreibung vorhanden</description>
<price />14.35</price>
<currency />CHF</currency>
<TDProductId>550284375</TDProductId>
<TDCategoryID>4</TDCategoryID>
<TDCategoryName>Books</TDCategoryName>
<merchantCategoryName/>
<sku/>
<shortDescription/>
<promoText/>
<previousPrice/>
<warranty/>
<availability/>
<inStock/>
<shippingCost/>
<deliveryTime/>
<weight/>
<size/>
<brand/>
<model/>
<ean/>
<upc/>
<isbn/>
<condition/>
<mpn/>
<techSpecs/>
<manufacturer/>
<programName>Ex Libris AG</programName>
<programLogoPath>http://hst.tradedoubler.com/file/26320/logo/100/ex_libris_logo_100x50.gif</programLogoPath>
<programId>48665</programId>
<fields/>
</product>
</products>