[b]1. 打印XML文档中所有category节点[/b]
[b]2. 按条件查询获取/subCategories/subCategory节点的内容,进而遍历[/b]
$xmlDoc = new DOMDocument();
$xmlDoc->load("xml/category.xml");
$categories = $xmlDoc->getElementsByTagName("category");
print $xmlDoc->saveXML();
[b]2. 按条件查询获取/subCategories/subCategory节点的内容,进而遍历[/b]
$category = $_GET["category"];
$categoryName = $_GET["categoryName"];
$xmlDoc = new DOMDocument();
$xmlDoc->load("xml/subCategory.xml");
$xPath = new DOMXPath($xmlDoc);
$nodes = $xPath->query("/subCategories/subCategory[categoryId ='".$category."']");
for($i=0; $i<$nodes->length 0; $i++){
$subCategory = $nodes->item($i);
$ids = $subCategory->getElementsByTagName( "id" );
$id = $ids->item(0)->nodeValue;
}