XML文件:<?xml version="1.0" encoding="gb2312"?>
<books>
<book>
<author>金墉</author>
<title>武侠小说</title>
<publisher>科技出版社</publisher>
<renqi>30</renqi>
</book>
<book>
<author>赵晴</author>
<title>读者</title>
<publisher>文艺出版社</publisher>
<renqi>58</renqi>
</book>
<book>
<author>赵晴1</author>
<title>读者1</title>
<publisher>文艺出版社1</publisher>
<renqi>36</renqi>
</book>
</books>php文件:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ޱĵ</title>
</head><body>
<?php
$doc = new DOMDocument();
$doc->load( 'books.xml' );
$books = $doc->getElementsByTagName( "book" );
foreach( $books as $book )
{
$authors = $book->getElementsByTagName( "author" );
$author = $authors->item(0)->nodeValue;
$publishers = $book->getElementsByTagName( "publisher" );
$publisher = $publishers->item(0)->nodeValue; $titles = $book->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
foreach ($titles as $list1)
{
$title_list = $list1->firstChild->nodeValue;
//echo "===".$title_list."<br />";
}
$renqis =$book->getElementsByTagname("renqi");
$renqi =$renqis->item(0)->nodeValue; foreach($book->getElementsByTagName('renqi') as $list)
{
$value = $list->firstChild->nodeValue;
//echo $value."<br />";
}
// echo "$title - $author - $publisher - $renqi<br>";
// echo count($titles);
for($i = 0; $i < count($titles); $i++){
echo "<br>[" . $titles->item($i)->nodeValue . " ... " . $renqis->item($i)->nodeValue . "]<br>";
}
}
?> <div>
<table style="width: 606px">
<?
foreach( $books as $book )
{
$titles = $book->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
$renqis =$book->getElementsByTagname("renqi");
$renqi =$renqis->item(0)->nodeValue;
for($i = 0; $i < count($titles); $i++){
?>
<tr>
<td style="width: 105px; height: 11px">
<? echo $titles->item($i)->nodeValue ?></td>
<td colspan="1" style="width: 260px; height: 11px">
<table style="width: <?=($renqis->item($i)->nodeValue)*5 ?>px; background-color: #ffcc66">
<tr>
<td colspan="3" rowspan="3" style="width: 6px"> </td>
</tr>
<tr> </tr>
<tr> </tr>
</table> </td>
<td colspan="2" style="height: 11px"> </td>
</tr>
<?
}
}
?>
</table>
</div>
</body>
</html>怎么改变xml文件内的值呢请各位多多指教..谢谢 ...
<books>
<book>
<author>金墉</author>
<title>武侠小说</title>
<publisher>科技出版社</publisher>
<renqi>30</renqi>
</book>
<book>
<author>赵晴</author>
<title>读者</title>
<publisher>文艺出版社</publisher>
<renqi>58</renqi>
</book>
<book>
<author>赵晴1</author>
<title>读者1</title>
<publisher>文艺出版社1</publisher>
<renqi>36</renqi>
</book>
</books>php文件:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ޱĵ</title>
</head><body>
<?php
$doc = new DOMDocument();
$doc->load( 'books.xml' );
$books = $doc->getElementsByTagName( "book" );
foreach( $books as $book )
{
$authors = $book->getElementsByTagName( "author" );
$author = $authors->item(0)->nodeValue;
$publishers = $book->getElementsByTagName( "publisher" );
$publisher = $publishers->item(0)->nodeValue; $titles = $book->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
foreach ($titles as $list1)
{
$title_list = $list1->firstChild->nodeValue;
//echo "===".$title_list."<br />";
}
$renqis =$book->getElementsByTagname("renqi");
$renqi =$renqis->item(0)->nodeValue; foreach($book->getElementsByTagName('renqi') as $list)
{
$value = $list->firstChild->nodeValue;
//echo $value."<br />";
}
// echo "$title - $author - $publisher - $renqi<br>";
// echo count($titles);
for($i = 0; $i < count($titles); $i++){
echo "<br>[" . $titles->item($i)->nodeValue . " ... " . $renqis->item($i)->nodeValue . "]<br>";
}
}
?> <div>
<table style="width: 606px">
<?
foreach( $books as $book )
{
$titles = $book->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
$renqis =$book->getElementsByTagname("renqi");
$renqi =$renqis->item(0)->nodeValue;
for($i = 0; $i < count($titles); $i++){
?>
<tr>
<td style="width: 105px; height: 11px">
<? echo $titles->item($i)->nodeValue ?></td>
<td colspan="1" style="width: 260px; height: 11px">
<table style="width: <?=($renqis->item($i)->nodeValue)*5 ?>px; background-color: #ffcc66">
<tr>
<td colspan="3" rowspan="3" style="width: 6px"> </td>
</tr>
<tr> </tr>
<tr> </tr>
</table> </td>
<td colspan="2" style="height: 11px"> </td>
</tr>
<?
}
}
?>
</table>
</div>
</body>
</html>怎么改变xml文件内的值呢请各位多多指教..谢谢 ...
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货