現有的PHP代碼輸出XML節點時,只能輸出第一個同名節點內容"100". 請問怎樣才能輸出所有節點的內容呢?
現有代碼:
/* $xmlstring 原內容:
-
id*cn
100
101
102
103
105
*/
$xmldoc = new DOMDocument();
$xmldoc->loadXML($xmlstring);
$users = $xmldoc->getElementsByTagName('GetUserInfo');
foreach ($users as $user) {
$html .= 'outputCustomer:'.get_txt($user,'Customer').'
';$html .= 'outputGeo:'.get_txt($user,'GeocallCLI').'
';
}
echo $html;
function get_txt($parent, $name) {
$nodes = $parent->getElementsByTagName($name);return $nodes->item(0)->nodeValue;
}
?>
另問怎樣只輸出 idcn節點中號前面部份, 即 id 而不是 id*cn
回複內容:
現有的PHP代碼輸出XML節點時,只能輸出第一個同名節點內容"100". 請問怎樣才能輸出所有節點的內容呢?
現有代碼:
/* $xmlstring 原內容:
-
id*cn
100
101
102
103
105
*/
$xmldoc = new DOMDocument();
$xmldoc->loadXML($xmlstring);
$users = $xmldoc->getElementsByTagName('GetUserInfo');
foreach ($users as $user) {
$html .= 'outputCustomer:'.get_txt($user,'Customer').'
';$html .= 'outputGeo:'.get_txt($user,'GeocallCLI').'
';
}
echo $html;
function get_txt($parent, $name) {
$nodes = $parent->getElementsByTagName($name);return $nodes->item(0)->nodeValue;
}
?>
另問怎樣只輸出 idcn節點中號前面部份, 即 id 而不是 id*cn
自己頂上, 哪位大俠能解答下麼
我頂