private
function
writeOrgin(){<br />
$article_array
=
array
(<br />
"第一篇"
=>
array
(<br />
"title"
=>
"PHP访问MySql数据库 初级篇"
,<br />
"link"
=>
"http://blog.csdn.net/morewindows/article/details/7102362"
<br />
),<br />
"第二篇"
=>
array
(<br />
"title"
=>
"PHP访问MySql数据库 中级篇 Smarty技术"
,<br />
"link"
=>
"http://blog.csdn.net/morewindows/article/details/7094642"
<br />
),<br />
"第三篇"
=>
array
(<br />
"title"
=>
"PHP访问MySql数据库 高级篇 AJAX技术"
,<br />
"link"
=>
"http://blog.csdn.net/morewindows/article/details/7086524"
<br />
),<br />
);<br />
$dom
=
new
DOMDocument(
'1.0'
,
'UTF-8'
);<br />
$dom
->formatOutput = true;<br />
$rootelement
=
$dom
->createElement(
"MoreWindows"
);<br />
foreach
(
$article_array
as
$key
=>
$value
)<br />
{<br />
$article
=
$dom
->createElement(
"article"
,
$key
);<br />
$title
=
$dom
->createElement(
"title"
,
$value
[
'title'
]);<br />
$link
=
$dom
->createElement(
"link"
,
$value
[
'link'
]);<br />
$article
->appendChild(
$title
);<br />
$article
->appendChild(
$link
);<br />
$rootelement
->appendChild(
$article
);<br />
}<br />
$dom
->appendChild(
$rootelement
);<br />
$filename
=
"D:\\test.xml"
;<br />
echo
'XML文件大小'
.
$dom
->save(
$filename
) .
'字节'
;<br />
<br />
}*/<br />
/*<br />
private
function
readOrgin(){<br />
$filename
=
"D:\\test.xml"
;<br />
$article_array
=
array
();<br />
<br />
$dom
=
new
DOMDocument(
'1.0'
,
'UTF-8'
);<br />
$dom
->load(
$filename
);<br />
<br />
$articles
=
$dom
->getElementsByTagName(
"article"
);<br />
echo
'<article> 结点个数 '
.
$articles
->length;<br />
foreach
(
$articles
as
$article
)<br />
{<br />
$id
=
$article
->getElementsByTagName(
"id"
)->item(0)->nodeValue;<br />
$title
=
$article
->getElementsByTagName(
"title"
)->item(0)->nodeValue;<br />
$link
=
$article
->getElementsByTagName(
"link"
)->item(0)->nodeValue;<br />
$article_array
[
$id
] =
array
(
'title'
=>
$title
,
'link'
=>
$link
);<br />
}<br />
<br />
echo
"<pre class="
brush:php;toolbar:false
">"
;<br />
var_dump(
$article_array
);<br />
echo
"