平成29年9月10日(日曜日)
php DOMDocument nodeName property returning ‘#text’ with the nodeName
$dom = new DOMDocument(); $dom->loadXML($stringXML); $valorizador = $dom->getElementsByTagName("tagname"); foreach ($valorizador->item(0)->childNodes as $item) { $childs = $item->childNodes; $key = $item->nodeName; foreach ($childs as $i) { echo $key." => ".$i->nodeValue. "\n"; } }
// 動作可 保存版 //----------------------------② //foreach ($xpath->query('.//c:AdvisoryPeriod', $node) as $child) { //foreach ($xpath->query('.//c:WarningPeriod', $node) as $child) { foreach ($xpath->query('.//c:WarningPeriod', $elements2) as $child) { echo $child->nodeName."②
"; echo $child->nodeValue."②
"; //----------------------------③ $node2 = $xpath->query('.//c:WarningPeriod', $node)->item(0); foreach ($xpath->query('.//c:EndTime', $node2) as $child) { echo $child->nodeName."③
"; echo $child->nodeValue."③
"; $Date_Term = $child->nodeName; //----------------------------④ $node3 = $xpath->query('.//c:EndTime', $node2)->item(0); foreach ($xpath->query('.//c:Date', $node3) as $child) { echo $child->nodeName."④
"; echo $child->nodeValue."④
"; } } }
$Property_count = 0; //----------------------------① Property foreach ($elements as $node) { echo $node-> nodeName . "①
"; $no = 0; //----------------------------② Type WarningPeriod AdvisoryPeriod foreach ($node->childNodes as $j) { echo $j->nodeName." => ".$j->nodeValue."②
"; $k_array[$Property_count][$no] = array($j->nodeName => $j->nodeValue); $no++; //----------------------------③ EndTime OverTime if($j->childNodes != NULL) { foreach ($j->childNodes as $k) { if ($k->nodeName != "#text"){ echo $k->nodeName." => ".$k->nodeValue."③
"; $k_array[$Property_count][$no] = array($k->nodeName => $k->nodeValue); $no++; } //----------------------------④ Date Term if($k->childNodes != NULL) { foreach ($k->childNodes as $l) { if ($l->nodeName != "#text"){ echo $l->nodeName." => ".$l->nodeValue."④
"; $k_array[$Property_count][$no] = array($l->nodeName => $l->nodeValue); $no++; } } } //---------------------------- } } } $Property_count++; }