リンクをクリックするたびに値がないため、xml要素の属性値を取得できませんが、xmlid=
を表示すると属性値がありますが、これが発生するのはなぜですか?
これが私のPHPコードです:
<?php
function parse_recursive(SimpleXMLElement $element, $level = 0)
{
$indent = str_repeat('', $level);
$value = trim((string) $element);
$children = $element->children();
$attributes = $element->attributes();
echo '<ul>';
if(count($children) == 0 && !empty($value))
{
if($element->getName() == 'GroupName'){
echo '<li><a href="http://localhost:8080/test/test.php?id=';
if(count($attributes) > 0)
{
foreach($attributes as $attribute)
{
if($attribute->getName() == 'Id'){
echo $attribute;
}
}
}
echo '">'.$element.'</a></li>';
}
}
if(count($children))
{
foreach($children as $child)
{
parse_recursive($child, $level+1);
}
}
echo '</ul>';
}
$xml = new SimpleXMLElement('main.xml', null, true);
parse_recursive($xml);
?>
これが私のxml構造です: