在文档中心查找“使用PHP DOM-XML创建和解析XML文件”。
解决方案 »
- Zend 推出新开发套件 PHP码农也能开发iOS应用
- paypal快速方式(express checkout)结账,没有显示购物车详细信息
- set php的过程中遇到一个问题,请指教,谢谢
- 谁有IE6帮我看一下我都块改疯了
- 编码转换求助!
- 小妹求教php页面里如何post数据到另一个页面!!!!!!
- 在把mysql中的字段导入EXCEL时,如果是中文字符将出现无法读取文件的问题,在线等待答案
- 请问:如何在PHP中防问JS变量和函数与如何在JS中访问PHP变量和函数,类?
- 有个问题,朶 字在php里处理错误!
- 一个搜索框内2个form 2个按钮 如何实现?
- 如何挽救 MySQL 的服务!在线等待
- 我急!!SESSION 传递的问题??
class myxml
{
var $parser;
function myxml()
{
$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, "mycdata");
}
function tag_on($parser, $tag, $attributes)
{
$curr_line = xml_get_current_line_number($parser);
echo "<font color=red>parser=".$parser.";tag=".$tag.";attributes=".$attributes.";curr_line=".$curr_line."</font><br>";
if($curr_line==2)
{
echo "\n<tr>";
}
else
{
if($curr_line!=1)
{
$value = ($curr_line-3)%6;
echo "<font color=green>value=".$value."</font><br>";
switch((($curr_line-3)%6))
{
case 0:
echo "\n<tr>";
break;
case 1:
echo "\n<td>";
break;
case 2:
echo "\n<td>";
break;
case 3:
echo "\n<td>";
break;
case 4:
echo "\n<td>";
break;
case 5:
break;
}
}
}
}
function tag_off($parser, $tag)
{
$curr_line = xml_get_current_line_number($parser);
if($curr_line!=1 && $curr_line!=2)
{
switch((($curr_line-3)%6))
{
case 0:
break;
case 1:
echo "</td>";
break;
case 2:
echo "</td>";
break;
case 3:
echo "</td>";
break;
case 4:
echo "</td>";
break;
case 5:
echo "\n</tr>";
break;
}
}
}
function mycdata($parser, $cdata)
{
echo $cdata;
}
function parse($data)
{
xml_parse($this->parser,$data);
}
}$xml_parser = new myxml();
$xmlfilename = "students.xml";
$fp = fopen($xmlfilename, "r");
$xmldata = fread($fp, filesize($xmlfilename));echo "<table border=1 width=100%>";
echo "<tr>";
echo "<td>id</td>";
echo "<td>name</td>";
echo "<td>password</td>";
echo "<td>test</td>";
echo "</tr>";
$xml_parser->parse($xmldata);
echo "</table>";
?>
<USERMANAGEMENT>
<students>
<student>
<id>1</id>
<name>aa</name>
<password>password</password>
<test>test</test>
</student>
<student>
<id>2</id>
<name>bb</name>
<password>password</password>
<test>test</test>
</student>
<student>
<id>3</id>
<name>cc</name>
<password>password</password>
<test>test</test>
</student>
</students>
</USERMANAGEMENT>
</XML><table border=1 width=100% id='studentslist' datapagesize='20' datasrc='#studentsinfo'>
<thead>
<tr>
<td>id</td>
<td>name</td>
<td>password</td>
</tr>
<tbody>
<tr>
<td><span datafld='id'></span></td>
<td><span datafld='name'></span></td>
<td><span datafld='password'></span></td>
</tr>
<tfoot>
<tr>
<td width="600" colspan="3">
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="first.gif" onclick="languagelist.firstPage()">
</td>
<td>
<img src="back.gif" onclick="languagelist.previousPage()">
</td>
<td>
<img src="next.gif" onclick="languagelist.nextPage()">
</td>
<td>
<img src="last.gif" onclick="languagelist.lastPage()">
</td>
</tr>
</table>
</td>
</tr>
</table>