新手发个php修改XML的问题!!
<br />$dom=new DOMDocument('1.0');<br />$dom->load('ceshi.xml');<br />$root=$dom->getElementsByTagName('online');<br />$root=$root->item(0);<br />$userid=$root->getElementsByTagName('userid');<br />foreach($userid as $b)<br />{<br /> foreach($b->attributes as $attr){ <br /><br />$value=$attr->nodeValue;<br />$name[].=$attr->nodeName;<br />{if($value=="xiao")<br />{ <br /> print_r($name); <br /><br />}<br /><br /> }<br />}<br /><br />}<br />$dom->save('ceshi.xml');<br /><br />
Copy after login
来个xml
<br /><br /><?xml version="1.0"?><br /><online> <br /><userid time="2007-06-13 11:20:08" ip="wangqile" label="wang">xiaxin</userid> <br /><userid time="2007-06-13 13:22:15" pp="dasdsa" label="xiao" ip="dasdsa">rwet</userid> <br /><userid time="2007-06-13 17:17:00" ip="dasdsa" label="ji"> gaoji</userid> <br /></online><br /><br /><br />
Copy after login
问题是按上面那种写法只循环label="xiao"的那一行,也就是只返回那一行nodename值。。
要是按上面写的话返回的是第一行第二行一起返回的nodename值。。我也没想出来怎么改~~新手求教啊!!!
------解决方案--------------------本帖最后由 xuzuning 于 2013-04-20 10:25:31 编辑 这个意思?
$dom=new DOMDocument('1.0');<br />$dom->load('ceshi.xml');<br />$root=$dom->getElementsByTagName('online');<br />$root=$root->item(0);<br />$userid=$root->getElementsByTagName('userid');<br />foreach($userid as $b) {<br /> if($b->attributes->getNamedItem('label')->nodeValue == 'xiao') {<br /> foreach($b->attributes as $attr){<br /> $res[$attr->nodeName] = $attr->nodeValue;<br /> }<br /> print_r($res);<br /> }<br />}<br />
Copy after login
Array
(
[time] => 2007-06-13 13:22:15
[pp] => dasdsa
[label] => xiao
[ip] => dasdsa
)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31