我正在测试一个 xml 对象以查看它深入了多少层,发现它深入了 11 个元素。我想知道如何才能更简单地完成此操作,以便将来可以节省几分钟。
$xml = simplexml_load_file(drupal_get_path('module', 'my_module') . '/test_file.xml');
dpm($xml);
foreach($xml->section as $section_l1) {
dpm('L1-------------------------------');
foreach($section_l1->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l1->section as $section_l2) {
dpm('---L2--------------------------');
foreach($section_l2->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l2->section as $section_l3) {
dpm('------L3---------------------');
foreach($section_l3->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l3->section as $section_l4) {
dpm('------L4---------------------');
foreach($section_l4->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l4->section as $section_l5) {
dpm('------L5---------------------');
foreach($section_l5->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l5->section as $section_l6) {
dpm('------L6---------------------');
foreach($section_l6->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l6->section as $section_l7) {
dpm('------L7---------------------');
foreach($section_l7->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l7->section as $section_l8) {
dpm('------L8---------------------');
foreach($section_l8->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l8->section as $section_l9) {
dpm('------L9---------------------');
foreach($section_l9->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l9->section as $section_l10) {
dpm('------L10---------------------');
foreach($section_l10->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l10->section as $section_l11) {
dpm('------L11---------------------');
foreach($section_l11->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l11->section as $section_l12) {
dpm('------L12---------------------');
foreach($section_l12->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
dpm('-----:');
foreach($section_l12->section as $section_l13) {
dpm('------L13---------------------');
foreach($section_l13->attributes() as $a => $b) {
dpm($a . ' = ' . $b);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
注意:drupal_get_path 和 dpm 是 Drupal CMS 函数,这里可以忽略。