2016-08-29 2 views
0

적 예 : HTML :XPath의 노드에서 둘 이상의 속성을 읽는 방법?

<div id="1" class="op" style='display: none;'> 
<h4>a</h4> 
<h4 >b</h4> 
</div> 

검색어 :

$elements = $xpath->query("//div[@id='1']@style='display:none;']/@id/@style"); 


echo @id 
echo @style 

하지만 작동하지 않습니다!

+0

당신이 폐쇄'['과'이 누락 '표시 : 없음;' '==' '표시! 없음; '' – Ghost

답변

0

당신은 당신의 쿼리에 [ 누락 오타를 사용할 normalize-space :

$elements = $xpath->query("//div[@id='1'][normalize-space(@style = 'display: none;')]"); 
if($elements->length > 0) { 
    echo $elements->item(0)->getAttribute('class'); 
    // foreach($elements as $e) { 

    // } 
} 
관련 문제