This book is really torture Ah, today saw the XML parsing part, the article in the introduction of functions and their parameters is very careful, but this did not put the source of the final write clearly, is always a small part, XML and PHP is not very sensitive to the case, can read out, today also encountered a garbled problem, Hope this aspect of the great God saw help to solve under, greatly appreciated Ah! The code in the book is posted below:
!--? php function Start ($parser, $element _name, $element _attrs)
{
switch ($element _name)
{
Case "book":
Echo --------
"; The contents of this paragraph also do not show
break;
Case "TITLE":
Echo "book Name:";
Break
Case "AUTHOR":
Echo "Author:";
Break
Case "ISBN":
Echo "ISBN:";
Break
Case "DATA":
Echo "Publication date:";
Break
Case ' price ':
echo "book Prices:";
Break
}
}
Function Stop ($parser, $element _name)
{
echo "
";
}
Function char ($parser, $data)
{
echo $data;
}
$parser =xml_parser_create ();
Xml_set_element_handler ($parser, "Start", "Stop");
Xml_set_character_data_handler ($parser, "char");
$fp =fopen ("Book.xml", "R");
while ($data =fread ($fp, 4096))
{
Xml_parse ($parser, $data, feof ($fp)) or
Die (the sprintf ("XML Error:%s at Line%d ",
Xml_error_string (Xml_get_error_code ($parser)),
Xml_get_current_line_number ($parser)));
}
Xml_parser_free ($parser);
?
Book.xml's code is as follows:
JavaScript language Essence
Crockford,d
9787121177408
2012.9
49.00 USD
The above describes the "flex+php RIA Application Development actual combat-Liang Edition" learning Diary 2, including the content of the aspects, I hope that the PHP tutorial interested in a friend helpful.