This stuff got me a day ... But in the end it was impossible to realize the effect that I had imagined ... It's a pity ... It seems that PHP also need to strengthen the XML ... If there's any research on this. Welcome Letter to discuss ...
First build the table:
CREATE TABLE Books (
BookID Int (4) not NULL auto_increment,
BookName varchar (+) not NULL,
Bookauth varchar () not NULL,
Bookpublisher varchar () not NULL,
Bookpubdate datetime not NULL,
Bookurl varchar () not NULL,
KEY BookID (BookID),
);
And then... This is the source code that translates data from MySQL into XML:
$connect _id=mysql_connect ("localhost", "root", "");
mysql_select_db ("BBS", $connect _id);
$query = "SELECT * from Books ORDER by BookID";
$rs =mysql_query ($query, $connect _id);
$numfields =mysql_num_fields ($RS);
$XMLfile = " n";
$XMLfile. = " n";
while ($row =mysql_fetch_array ($rs)) {
for ($i =0; $i < $numfields; $i) {
$fieldname =mysql_field_name ($rs, $i);
$XMLfile. = "<". $fieldname. ">". $row [$i]. " n";
}
}
Mysql_free_result ($RS);
Mysql_close ($connect _id);
$XMLfile. = "n";
$FP =fopen ("Xmldoc/xmldoc.xml", "w");
if (fwrite ($FP, $XMLfile)) {
echo "Write file successfully!";
}
else{
echo "Writing file failed!";
}
?>
This is the source code that takes data from XML into HTML ...
Class xml{
var $parser;
function XML () {
$this->parser = Xml_parser_create ();
Xml_set_object ($this->parser,& $this);
Xml_set_element_handler ($this->parser, "tag_on", "Tag_off");
Xml_set_character_data_handler ($this->parser, "CDATA");
}
Function Parse ($data) {
Xml_parse ($this->parser, $data);
}
function tag_on ($parser, $tag, $attributes) {
if (Xml_get_current_line_number ($parser) ==2) {
echo "". $tag. "";
}
else{
Switch ((Xml_get_current_line_number ($parser)-2)%6) {
Case 0:
echo "Download";
Break
Case 1:
echo "ID number";
Break
Case 2:
echo "title";
Break
Case 3:
echo "Author";
Break
Case 4:
echo "Publishing House";
Break
Case 5:
echo "Publication date";
Break
}
}
}
function CDATA ($parser, $cdata) {
Echo $cdata;
}
function Tag_off ($parser, $tag) {
echo "n";
}
}
$XML _parser = new XML ();
$XMLfilename = "Xmldoc/xmldoc.xml";
$FP =fopen ($XMLfilename, "R");
$XMLdata =fread ($fp, FileSize ($XMLfilename));
?>
Book Information
$XML _parser->parse ($XMLdata);? >
In fact, you should see. This example is a failure of the dongdong ... Because the effect is not big. Don't get what you want ... Alas... Bitter....
http://www.bkjia.com/PHPjc/508362.html www.bkjia.com true http://www.bkjia.com/PHPjc/508362.html techarticle this stuff got me a day ... But in the end it was impossible to realize the effect that I had imagined ... It's a pity ... It seems that PHP also need to strengthen the XML ... If any ...