时间:2021-07-01 10:21:17 帮助过:2人阅读
http://114.80.235.12 http://114.80.236.202
//2.读xml$xml_array=simplexml_load_file("wc.xml"); //将XML中的数据,读取到数组对象中foreach($xml_array AS $temp){echo ""; print_r($temp->f);echo "";}
xpath='//f[2]/text()'
xpath='//f[2]/text()'
谢谢了,能不能再麻烦你说的明确一下,我百度了一个,没有东西
print_r($xml_array->a->f);
$s =<<< XML均可得到XML;$xml = simplexml_load_string($s);//正常遍历,需要确切的知道目标节点所在层次foreach($xml AS $temp){ foreach($temp->f as $v) echo "$v http://114.80.235.12 http://114.80.236.202
xpath('//f') as $v) echo "$v
";
[code=php]$s =<<< XML
谢谢大哥相助。祝你天天快乐。
我想再加强学习一下,请问这是哪方面的知识?我应该搜索什么知识啊?谢谢了。
如果你 print_r($xml_array); 就可看到
SimpleXMLElement Object( [@attributes] => Array ( [time] => 180530 [vi] => 1 [ch] => 29 [nls] => 0 [title] => 监控实拍 [code] => qT4j-61ws-Q [enable] => 1 [logo] => 0 [wt] => 0 [band] => 0 ) [a] => SimpleXMLElement Object ( [f] => Array ( [0] => http://114.80.235.12 [1] => http://114.80.236.202 ) ) [b] => SimpleXMLElement Object ( ))这样的结构,依此书写代码是很容易的。不再赘述
http://114.80.235.12 http://114.80.236.202 XML; $doc = new DOMDocument();$doc->loadXML($s);$xpath = new DOMXPath($doc);$query = '//f[1]/text()';$entries = $xpath->evaluate($query, $doc);// foreach ($entries as $entry) var_dump($entry);foreach ($entries as $entry) echo $entry->data;$xml = simplexml_load_string($s);foreach($xml->xpath('//f[1]/text()') as $v) echo $v;?>
呃,是第二个地址吧?#1的才正确
//f[ 2]/text()
xpath的计数器是从1开始的