日期:2014-05-17 浏览次数:20414 次
<timezone>
<id>hell</id>
<raw_offset>2</raw_offset>
<dst>
<start_month>02</start_month>
<start_day>29</start_day>
<start_day_of_week>00</start_day_of_week>
<start_time_hour>02</start_time_hour>
<start_time_minute>00</start_time_minute>
<end_month>09</end_month>
<end_day>06</end_day>
<end_day_of_week>00</end_day_of_week>
<end_time_hour>02</end_time_hour>
<end_time_minute>00</end_time_minute>
</dst>
</timezone>
private function writeOrgin(){
//将数组输出到XML文件中
// by MoreWindows( http://blog.csdn.net/MoreWindows )
$article_array = array(
"第一篇" => array(
"title"=>"PHP访问MySql数据库 初级篇",
"link"=>"http://blog.csdn.net/morewindows/article/details/7102362"
),
"第二篇" => array(
"title"=>"PHP访问MySql数据库 中级篇 Smarty技术",
"link"=>"http://blog.csdn.net/morewindows/article/details/7094642"
),
"第三篇" => array(
"title"=>"PHP访问MySql数据库 高级篇 AJAX技术",
"link"=>"http://blog.csdn.net/morewindows/article/details/7086524"
),
);
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$rootelement = $dom->createElement("MoreWindows");
foreach ($article_array as $key=>$value)
{
$article = $dom->createElement("article", $key);
$title = $dom->createElement("title", $value['title']);
$link = $dom->createElement("link", $value['link']);
$article->appendChild($title);
$article->appendChild($link);
$rootelement->appendChild($article);
}
$dom->appendChild($rootelement);
$filename = "D:\\test.xml";
echo 'XML文件大小' . $dom->save($filename) . '字节';
}*/
// 不使用
/*
private function readOrgin(){
$filename = "D:\\test.xml";
$article_array = array();
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->load($filename);
//得到<article>结点
$articles = $dom->getElementsByTagName("article");
echo '<article> 结点个数 ' . $articles->length;
foreach ($articles as $article)
{
$id = $article->getElementsByTagName("id")->item(0)->nodeValue;
$title = $article->getElementsByTagName("title")->item(0)->nodeValue;
$link = $article->getElementsByTagName("link")->item(0)->nodeValue;
$article_array[$id] = array('title'=>$title, 'link'=>$link);
}
//输出结果
echo "<pre>";
var_dump($article_array);
echo "</pre>";
}