-4

XML の読み取りについて簡単なヘルプが必要です。ツールチップに結果を表示しており、すべての準備ができています。各ロットを id で 1 つずつクエリしたい。ロットごとに php コードが必要ですid ここに私の XML があります

<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;

    }

これだけでアドレスがわかります。リストされている他のすべての属性を取得するにはどうすればよいですか? ツールチップでこれを使用できるようになりました

    <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>
4

1 に答える 1

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

あなたは尋ねました:「これは私にアドレスを与えるだけです。リストされている他のすべての属性を取得するにはどうすればよいですか?」

Xpath では*、要素の具体的な名前を指定したくない場合は、スターを使用できます。

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

例: ZVON 例 3: アスタリスク * は、パスの前にあるすべての要素を選択します

しかし、あなたの質問は私には非常に明確ではなかったので、この答えは少し推測です. それがあなたを助けないなら、私を責めないでください;)

于 2013-02-13T10:01:49.950 に答える