2013-02-12 3 views
-4

내 xml을 읽는 데 도움이 필요합니다. 내 결과를 툴팁에 표시하고 모든 것이 준비되었습니다. ID별로 하나씩 로트를 하나씩 조회하려고합니다. 나는 id 가 여기 내 XML 여기xml 및 php - 텍스트 출력

<section id="8" number="8" name="Section 8" phase="4" date="2/11/2013"> 
<lot id="2198" lot="2" block="1" section="8"> 
<number>2</number> 
<legal>L2-B1-S8 (60')</legal> 
<address>12107 Arbor Blue Lane</address> 
<builder>Perry Homes</builder> 
<status>Sold</status> 
<plan>3158</plan> 
<brick>Acme-StoneBriar</brick> 
<trim>SW-Portbello, Tea Chest</trim> 
<final_inspection_date/> 
<completion>5/23/2013</completion> 
<sqft>3158</sqft> 
<stories>2</stories> 

<bed>4</bed> 
<bath>3</bath> 
<garage>3</garage> 
<lotwidth>60'</lotwidth> 
<specprice>Sold</specprice> 
<imglocation>none</imglocation> 
<premium>off</premium> 
</lot> 
<lot id="2218" lot="22" block="1" section="8"> 
<number>22</number> 
<legal>L22-B1-S8 (60')</legal> 
<address>19503 Bella Arbor Lane</address> 
<builder>Perry Homes</builder> 
<status>Sold</status> 
<plan>3391</plan> 
<brick>Hanson-Chestnut Hill</brick> 
<trim>SW-Virtual Taupe, Smokehouse</trim> 
<final_inspection_date>12/3/2012</final_inspection_date> 
<completion>11/28/2012</completion> 
<sqft>3391</sqft> 
<stories>2</stories> 
<bed>4</bed> 
<bath>3</bath> 
<garage>3</garage> 
<lotwidth>60'</lotwidth> 
<specprice>Sold</specprice> 
<imglocation>3391w-e51.png</imglocation> 
<premium>off</premium> 
</lot> 
</section> 

내 테스트 PHP 코드

$xmldoc = new DOMDocument(); 
    $xmldoc->load('mydata.xml'); 

    $xpathvar = new Domxpath($xmldoc); 

    $queryResult = $xpathvar->query('//lot[@id="2198"]/address'); 
    foreach($queryResult as $result){ 
      echo $result->textContent; 

    } 

이 그냥 나에게 주소를 제공입니다 그들의 각 로트에 PHP 코드가 필요합니다. 다른 모든 속성을 어떻게 나열합니까? 지금 당신은 질문이

<div style="float:left"> 

<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
"><label style="color:grey">Status: </label>'.$status.'</p> 
<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
"><label style="color:grey">Builder: </label>'.$builder.'</p> 
<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
    width:200px 
"><label style="color:grey">Address: </label>'.$address.'</p> 
<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
"><label style="color:grey">Square Ft: </label>'.$square.'</p> 
<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
"><label style="color:grey">Stories: </label>'.$stories.'</p> 

<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
"><label style="color:grey">Completion: </label>'.$completion.'</p> 


<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
"><label style="color:grey">Plan #: </label>'.$plan.'</p> 
<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
"><label style="color:grey">B/B/G: </label>'.$bed.'/'.$bath.'/'.$garage.'</p> 
<p style=" 
    margin: 0; 
    padding-left: 10px; 
    font-size: 13px; 
"><label style="color:grey">Spec Price: </label>'.$specprice.'</p> 


</div> 
+0

XPath의'/ address'를 다른 속성과 바꾸는 것은 어떻습니까? (또는 모두 원한다면'*') –

답변

0
//lot[@id="2198"]/address 

나의 툴팁에 사용할 수 : ". 이건 그냥 나에게 주소를 제공합니다 내가 어떻게합니까 다른 모든 속성이 나와?" 당신은 요소의 구체적인 이름을 지정하지 않는 경우

XPath는, 당신은 별 *를 사용할 수 있습니다

//lot[@id="2198"]/* 

예 : ZVON Example 3: The star * selects all elements located by preceeding path

그러나 귀하의 질문은 매우 명확하지 않았다 나에게이 대답은 약간의 추측이다.) 도움이되지 않으면 나를 비난하지 마십시오.)