时间:2021-07-01 10:21:17 帮助过:23人阅读
type="0">
$string = <<
type="0">
XML;
$xml = new SimpleXMLElement($string);
$result = $xml->xpath('//node/@name');
while(list( , $node) = each($result)) {
echo '@name: ',$node,"\n";
}
$result = $xml->xpath('//node/@id');
while(list( , $node) = each($result)) {
echo '@id: ',$node,"\n";
}
$result = $xml->xpath('//node[@type=1]/../@id');
while(list( , $node) = each($result)) {
echo '@部门的parent_id: ',$node,"\n";
}
$result = $xml->xpath('//node[@type=2]/../@id');
while(list( , $node) = each($result)) {
echo '@叶子的parent_id: ',$node,"\n";
}
?>
$s =<<< XML
type="0">
XML;
$xml = simplexml_load_string($s);
foreach($xml->node as $node) {
foreach($node->attributes() as $k=>$v) echo "$k => $v\n";
foreach($node->node as $node) {
foreach($node->attributes() as $k=>$v) echo "$k => $v\n";