0
xmlreaderを使ってxmlファイルを読み込んだ後、すべて正常に動作するデータベースにデータを渡すPHPスクリプトがあります。私はイメージに苦労しています。私は、各プロパティの最初のイメージを取得する方法を試すことしかできません。ここでphp xmlreaderすべての子ノードを取得
<properties>
<Property>
<propertyid>17229-122</propertyid>
<lastUpdateDate>2017-08-02</lastUpdateDate>
<category>Residential For Sale</category>
<images>
<image number="1">
<image>domain.com/imagefile1212.jpg</image>
<alttext/>
</image>
<image number="2">
<image>domain.com/imagefile12dfs2.jpg</image>
<alttext/>
</image>
<image number="3">
<image>domain.com/imagefile1212.jpg</image>
<alttext/>
</image>
</images>
私のPHPはこの
$theFeed = "locationofthexmlfile.xml";
$reader = new XMLReader();
$reader->open($theFeed);
while($reader->read()) {
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'Property') {
$propCount++;
// Get children of property
$doc = new DOMDocument();
$xml = simplexml_import_dom($doc->importNode($reader->expand(), true));
#### get the data
$ref = $xml->propertyid; // this works fine
$img1 = $xml->images->image->image; /// this gets the first image
?????? how to I get all the other images like $img2,$img3 etc
}
}
ようなXMLのサンプルがある私は、画像ノードのすべての子ノードを取得する方法を私の質問があると思いますか?しかし私はちょうどそれを私達の仕事を傾ける。または、私は、属性番号= '1'などを探して各画像をターゲットにする必要があります。
すべてのヘルプやポインタを大幅に私はすべてのノードへのアクセスを得るために「子どもを()」を使用することをお勧め
SimpleXMLに直接XMLをロードした場合と同じように、プロパティを反復したり、SimpleXMLElement :: xpath()を使用したりします。 * btw * '新しいDOMDocument()'はループの外になければならず、あなたは '$ reader-> expand()'の引数として渡すことができます - importNode()は不要です。 – ThW
ありがとうTWH私は今それを見てみましょう –