现在一个问题一个问题解决吧,先解决的是按照P中的C来排序,但是C中的属性是按照P来排序,但是怎么把B,S,T中的值也给去出来,看显示结果如下:am002 0855 0920 50 0 1 330 1 -- T3 --50 H A T --950 L 5 5 --1040 Y A A --1700 f A A am005 0755 1120 50 0 1 330 1 -- T3 --100 Y A A --1700 F A A am004 0455 0620 50 0 1 330 1 -- T3 . . . 等
http://topic.csdn.net/u/20090312/09/5e65106b-7c21-4c34-8536-a6a4e8f24bbb.html
再问吧
<?php
header("Content-Type:text/html;charset=UTF-8");
$doc = new DOMDocument; //xml?始解析
$doc->load("5.xml");
$book = $doc->documentElement;
$airline = $book->getElementsByTagName('airline');
//echo $airline->length-1;
$list = array();
$minP = array();foreach($airline as $c)
{
$stime = $c->GetAttributeNode('stime')->nodeValue;
$id = $c->GetAttributeNode('id')->nodeValue;
$atime = $c->GetAttributeNode('atime')->nodeValue;
$airrax = $c->GetAttributeNode('airrax')->nodeValue;
$fulerax = $c->GetAttributeNode('fulerax')->nodeValue;
$food = $c->GetAttributeNode('food')->nodeValue;
$dfly = $c->GetAttributeNode('dfly')->nodeValue;
$type = $c->GetAttributeNode('type')->nodeValue;
$et = $c->GetAttributeNode('et')->nodeValue;
$stn = $c->GetAttributeNode('stn')->nodeValue;
$atn = $c->GetAttributeNode('atn')->nodeValue; $list[$id][$stime]['stime'] = $stime;
$list[$id][$stime]['atime'] = $atime;
$list[$id][$stime]['airrax'] = $airrax;
$list[$id][$stime]['fulerax'] = $fulerax;
$list[$id][$stime]['food'] = $food;
$list[$id][$stime]['dfly'] = $dfly;
$list[$id][$stime]['type'] = $type;
$list[$id][$stime]['et'] = $et;
$list[$id][$stime]['stn'] = $stn;
$list[$id][$stime]['atn'] = $atn;/*
$index = 0;
$childnodes = $c->getElementsByTagName('c');
$id = $c->getAttributeNode('id')->nodeValue;
for($i=$childnodes->length-1; $i>=0;$i--) {
$nixiang=$childnodes->item($i)->GetAttributeNode('p')->nodeValue;
if ($nixiang!="0")
{
$list[$id][$index] = $childnodes->item($i)->GetAttributeNode('p')->nodeValue;
$index++;
}
}
sort($list[$id]);
$minP[$id] = $list[$id][0];
*/
}sort($list[$id][$stime]);
print_r($list);?>经测试没问题测试结果如下:
Array ( [am001] => Array ( [0755] => Array ( [stime] => 0755 [atime] => 1020 [airrax] => 50 [fulerax] => 0 [food] => 1 [dfly] => 1 [type] => 330 [et] => 1 [stn] => -- [atn] => T3 ) ) [am002] => Array ( [0855] => Array ( [stime] => 0855 [atime] => 0920 [airrax] => 50 [fulerax] => 0 [food] => 1 [dfly] => 1 [type] => 330 [et] => 1 [stn] => -- [atn] => T3 ) ) [am003] => Array ( [0955] => Array ( [stime] => 0955 [atime] => 1120 [airrax] => 50 [fulerax] => 0 [food] => 1 [dfly] => 1 [type] => 330 [et] => 1 [stn] => -- [atn] => T3 ) ) [am004] => Array ( [0455] => Array ( [stime] => 0455 [atime] => 0620 [airrax] => 50 [fulerax] => 0 [food] => 1 [dfly] => 1 [type] => 330 [et] => 1 [stn] => -- [atn] => T3 ) ) [am005] => Array ( [0755] => Array ( [0] => -- [1] => 0 [2] => 1 [3] => 1 [4] => 1 [5] => 50 [6] => 330 [7] => 0755 [8] => 1120 [9] => T3 ) ) ) 楼主给分吧
am002 0755 1020 50 .....等等
--50
--950
--1040
--1700
.
.
.
.
这样显示,你那解析出来只是airline中的属性,我也要那个airline/c中的属性值p也要显示啊;
现在爷节点是按照id排序的,子节点是按照c来排序的.<?php
header("Content-Type:text/html;charset=UTF-8");
$doc = new DOMDocument; //xml始解析
$doc->load("5.xml");
$book = $doc->documentElement;
$airline = $book->getElementsByTagName('airline');
//echo $airline->length-1;
$list = array();
$minP = array();
$attribute = array();$arrAttribute = array("id", "stime", "atime", "airrax", "fulerax", "food", "dfly", "type", "et", "stn", "atn");foreach($airline as $c)
{
$index = 0;
$childnodes = $c->getElementsByTagName('c');
$id = $c->getAttributeNode('id')->nodeValue;
foreach($arrAttribute as $key=>$value)
{
$attribute[$id][$value] = $c->getAttribute($value);
}
for($i=$childnodes->length-1; $i>=0;$i--)
{
$nixiang=$childnodes->item($i)->GetAttributeNode('p')->nodeValue;
if ($nixiang!="0")
{
$list[$id][$index] = $childnodes->item($i)->GetAttributeNode('p')->nodeValue;
$index++;
}
}
sort($list[$id]);
$minP[$id] = $list[$id][0];
}asort($minP);
$mid=0;
foreach($minP as $id => $val)
{
foreach($attribute[$id] as $value)
{
echo $value . "\t";
}
for ($i = 0; $i<count($list[$id]); $i++)
echo "--".$list[$id][$i]."<br>";
$mid++;
}
<?
header("Content-Type:text/html;charset=UTF-8");
$doc = new DOMDocument; //xml?始解析
$doc->load("book.xml");
$book = $doc->documentElement;
$airline = $book->getElementsByTagName('airline');
//echo $airline->length-1;
$list = array();
$minP = array();
$arr = array(); //++
$index1 = 0;
foreach($airline as $c)
{
$index = 0;
$childnodes = $c->getElementsByTagName('c');
$id = $c->getAttributeNode('id')->nodeValue;
$pro = array();//++
$pro[0] = $id;
$pro[1] = $c->getAttribute('stime');
$pro[2] = $c->getAttribute('atime');
$pro[3] = $c->getAttribute('airrax');
$pro[4] = $c->getAttribute('fulerax');
$pro[5] = $c->getAttribute('food');
$pro[5] = $c->getAttribute('dfly');
$pro[6] = $c->getAttribute('type');
$pro[7] = $c->getAttribute('et');
$pro[8] = $c->getAttribute('stn');
$pro[9] = $c->getAttribute('atn');
$arr[$index1] = $pro;
$index1++;
for($i=$childnodes->length-1; $i>=0;$i--) {
$nixiang=$childnodes->item($i)->GetAttributeNode('p')->nodeValue;
if ($nixiang!="0")
{
$list[$id][$index] = $childnodes->item($i)->GetAttributeNode('p')->nodeValue;
$index++;
}
}
sort($list[$id]);
$minP[$id] = $list[$id][0];
}asort($minP);
$mid=0;
foreach($minP as $id => $val)
{echo $id." ";
for($i = 0;$i < count($arr);$i++){
for($j = 1; $j < count($arr[$i]);$j++){
if($arr[$i][0]==$id){
echo $arr[$i][$j]." ";
}
}
}
echo "<br>";
for ($i = 0; $i<count($list[$id]); $i++)
echo "--".$list[$id][$i]."<br>";
$mid++;
}?>
--50 H A T
--950 L 5 5
--1040 Y A A
--1700 f A A
am005 0755 1120 50 0 1 330 1 -- T3
--100 Y A A
--1700 F A A
am004 0455 0620 50 0 1 330 1 -- T3
.
.
.
等