2012-04-26 6 views
-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 통과하면, 출력은 아래와 같습니다 있도록 I 출력이 필요합니다조건으로 'ID'이 XML을 구문 분석하는 PHP 스크립트를 필요

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

StackOverflow에 오신 것을 환영합니다. 여기에 질문하는 방법에 대한 지침은 [FAQ] (http://stackoverflow.com/faq) 및 특히 [어떻게 질문합니까?] (http://stackoverflow.com/faq#howtoask)를 참조하십시오. . –

+2

기초를 확인하십시오 http://php.net/manual/en/ref.xml.php – ray

+0

또는 더 기본적인 ... http://www.php.net/manual/en/simplexml.examples-basic.php – Gustav

답변

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 />'; 
    } 
} 
?> 

희망이 도움이됩니다.

+0

정말 고맙습니다 pushpesh ... 당신은 훌륭한 PHP 프로그래머 여야합니다 – user1357931