-2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Catalog SYSTEM "http://store.yahoo.com/doc/dtd/Catalog.dtd">
<Catalog StoreID="yhst-34564052343" StoreName="test.com" PublishTimestamp="1332786206">
<Item ID="10170090" TableID="yd-item">
<ItemField TableFieldID="more-image3" Value="test1"/>
<ItemField TableFieldID="price-range" Value="23"/>
<ItemField TableFieldID="more-image4" Value="test2"/>
<ItemField TableFieldID="name" Value="Liquid Light Drop 1 Pendant Light"/>
</Item>
 <Item ID="10170191" TableID="yd-item">
<ItemField TableFieldID="more-image3" Value="test3"/>
<ItemField TableFieldID="price-range" Value="34"/>
<ItemField TableFieldID="more-image4" Value="test4"/>
<ItemField TableFieldID="name" Value="Liquid Light Drop 4 Pendant Light"/>
</Item>
</Catalog>

ID 10170191が合格した場合、出力が次のようになるように出力する必要があります。

more-image3:-test3
price-range:-34
more-image4:-test4
name:-Liquid Light Drop 4 Pendant Light
4

1 に答える 1

0

これを試して:

<?php
$xml='<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Catalog SYSTEM "http://store.yahoo.com/doc/dtd/Catalog.dtd">
<Catalog StoreID="yhst-34564052343" StoreName="test.com" PublishTimestamp="1332786206">
<Item ID="10170090" TableID="yd-item">
<ItemField TableFieldID="more-image3" Value="test1"/>
<ItemField TableFieldID="price-range" Value="23"/>
<ItemField TableFieldID="more-image4" Value="test2"/>
<ItemField TableFieldID="name" Value="Liquid Light Drop 1 Pendant Light"/>
</Item>
 <Item ID="10170191" TableID="yd-item">
<ItemField TableFieldID="more-image3" Value="test3"/>
<ItemField TableFieldID="price-range" Value="34"/>
<ItemField TableFieldID="more-image4" Value="test4"/>
<ItemField TableFieldID="name" Value="Liquid Light Drop 4 Pendant Light"/>
</Item>
</Catalog>';

$xml=simplexml_load_string( $xml );
$xpath=$xml->xpath( '//Catalog/Item[@ID="10170191"]' );
foreach( $xpath as $result ) {
    foreach( $result->ItemField as $path ) {
        echo $path['TableFieldID'] . ': ' . $path['Value'] . '<br />';
    }
}
?>

お役に立てれば。

于 2012-04-26T07:21:15.657 に答える