选择显示字体大小

用php实现动态产生xml文件以及从xml文件中抽取数据转化成html的小程序


这个东东搞了我一天。。。可是到最后发现却无法实现自己想像中的那种效果。。。真是可惜。。。看来phpxml还需要加强。。。如果哪位对此有研究。欢迎来信探讨。。。

首先建表:
create table books (
 bookid int(4) not null auto_increment,
 bookname varchar(100) not null,
 bookauth varchar(50) not null,
 bookpublisher varchar(50) not null,
 bookpubdate datetime not null,
 bookurl varchar(50) not null,
 key bookid (bookid),
);

然后。。。这段是从mysql里取数据转化成xml的源代码:
<?
&#36;connect_id=mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
mysql_select_db(&quot;bbs&quot;,&#36;connect_id);
&#36;query=&quot;select * from books order by bookid&quot;;
&#36;rs=mysql_query(&#36;query,&#36;connect_id);
&#36;numfields=mysql_num_fields(&#36;rs);
&#36;xmlfile=&quot;<?xml version=\&quot;1.0\&quot; encoding=\&quot;gb2312\&quot;?>\n&quot;;
&#36;xmlfile.=&quot;<books>\n&quot;;

while(&#36;row=mysql_fetch_array(&#36;rs)){
for(&#36;i=0;&#36;i<&#36;numfields;&#36;i++){
&#36;fieldname=mysql_field_name(&#36;rs,&#36;i);
&#36;xmlfile.=&quot;<&quot; . &#36;fieldname . &quot;>&quot; . &#36;row[&#36;i] . &quot;</&quot; . &#36;fieldname . &quot;>\n&quot;;
}
}
mysql_free_result(&#36;rs);
mysql_close(&#36;connect_id);
&#36;xmlfile.=&quot;</books>\n&quot;;
&#36;fp=fopen(&quot;xmldoc/xmldoc.xml&quot;,&quot;w&quot;);
if(fwrite(&#36;fp,&#36;xmlfile)){
echo &quot;写入文件成功!&quot;;
}
else{
echo &quot;写入文件失败!&quot;;
}
?>

这段是从xml里取数据转化成html的源代码。。。
<?
class xml{
var &#36;parser;

function xml(){
&#36;this->parser = xml_parser_create();
xml_set_object(&#36;this->parser,&&#36;this);
xml_set_element_handler(&#36;this->parser,&quot;tag_on&quot;,&quot;tag_off&quot;);
xml_set_character_data_handler(&#36;this->parser,&quot;cdata&quot;);
}

function parse(&#36;data){
xml_parse(&#36;this->parser,&#36;data);
}

function tag_on(&#36;parser,&#36;tag,&#36;attributes){
if(xml_get_current_line_number(&#36;parser)==2){
echo &quot;<tr><td colspan=\&quot;2\&quot; align=\&quot;center\&quot;>&quot; . &#36;tag . &quot;</td>&quot;;
}
else{
switch ((xml_get_current_line_number(&#36;parser)-2)%6){
case 0:
echo &quot;<tr><td>下载<td>&quot;;
break;
case 1:
echo &quot;<tr><td>id号<td>&quot;;
break;
case 2:
echo &quot;<tr><td>书名<td>&quot;;
break;
case 3:
echo &quot;<tr><td>作者<td>&quot;;
break;
case 4:
echo &quot;<tr><td>出版社<td>&quot;;
break;
case 5:
echo &quot;<tr><td>出版日期<td>&quot;;
break;
}
}
}

function cdata(&#36;parser,&#36;cdata){
echo &#36;cdata;
}

function tag_off(&#36;parser,&#36;tag){
echo &quot;\n&quot;;
}
}

&#36;xml_parser = new xml();
&#36;xmlfilename=&quot;xmldoc/xmldoc.xml&quot;;
&#36;fp=fopen(&#36;xmlfilename,&quot;r&quot;);
&#36;xmldata=fread(&#36;fp,filesize(&#36;xmlfilename));
?>
<html><head><title>图书信息</title></head>
<body>
<table border=&quot;0&quot; cellspacing=&quot;1&quot; cellpadding=&quot;2&quot; width=&quot;80%&quot; bgcolor=&quot;#b0d8ff&quot; align=&quot;center&quot;>
<?
&#36;xml_parser->parse(&#36;xmldata);
?>
</table>

其实你们应该看得出。。这个例子是个失败的东东。。。因为效果不大。。根本不能得到自己想要的东东。。。唉。。。苦。。。。

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons