$s =<<< XML
<Location>
<Continent Name="亚洲" Code="Asia">
<CountryRegion Name="中国" Code="1">
</CountryRegion>
<CountryRegion Name="阿富汗" Code="AFG">
</CountryRegion>
<CountryRegion Name="阿拉伯联合酋长国" Code="ARE">
</CountryRegion>
</Continent>
<Continent Name="欧洲" Code="Europe ">
<CountryRegion Name="阿尔巴尼亚" Code="ALB">
</CountryRegion>
<CountryRegion Name="爱尔兰" Code="IRL">
</CountryRegion>
</Continent>
</Location>
XML;
$doc = new DOMDocument();
$doc->loadxml( $s );
$lc = $doc->getElementsByTagName( "Continent" );
foreach($lc as $item) {
if($item->getAttribute("Name") == '亚洲') {
foreach($item->getElementsByTagName( "CountryRegion" ) as $node) {
echo $node->getAttribute("Name"), PHP_EOL;
}
}
}
中国
阿富汗
阿拉伯联合酋长国
<Location>
<Continent Name="亚洲" Code="Asia">
<CountryRegion Name="中国" Code="1">
</CountryRegion>
<CountryRegion Name="阿富汗" Code="AFG">
</CountryRegion>
<CountryRegion Name="阿拉伯联合酋长国" Code="ARE">
</CountryRegion>
</Continent>
<Continent Name="欧洲" Code="Europe ">
<CountryRegion Name="阿尔巴尼亚" Code="ALB">
</CountryRegion>
<CountryRegion Name="爱尔兰" Code="IRL">
</CountryRegion>
</Continent>
</Location>
XML;
$doc = new DOMDocument();
$doc->loadxml( $s );
$lc = $doc->getElementsByTagName( "Continent" );
foreach($lc as $item) {
if($item->getAttribute("Name") == '亚洲') {
foreach($item->getElementsByTagName( "CountryRegion" ) as $node) {
echo $node->getAttribute("Name"), PHP_EOL;
}
}
}
中国
阿富汗
阿拉伯联合酋长国
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货