PHP bir DOMNodeList ayrıştırma

0 Cevap php

Formatında bir web hizmeti dönüş Xml

<string>
  <NewDataSet>
    <DealBlotter>
      <CustomerReference>161403239</CustomerReference>
      <Symbol>EUR/USD</Symbol>
      <BuySell>S</BuySell>
      <ContractValue>-100000</ContractValue>
      <Price>1.35070</Price>
      <CounterValue>-135070</CounterValue>
      <TradeDate>2011-01-20 22:05:21.690</TradeDate>
      <ConfirmationNumber>78967117</ConfirmationNumber>
      <Status>C</Status>
      <lTID>111913820</lTID>
    </DealBlotter>
  </NewDataSet>
</string>

Şimdi ben bu erişmek ve Kıvrılmaları kullanıyorum -

$xml = simplexml_load_string($result);
$dom = new DOMDOcument();

// Load your XML as a string
$dom->loadXML($xml);

// Create new XPath object
$xpath = new DOMXpath($dom);

$res = $xpath->query("/NewDataSet/DealBlotter");

foreach($res as $node)
{
    print "i went inside foreach";
    $custref =  ($node->getElementsByTagName("CustomerReference")->item(0)->nodeValue);
    print $custref;
    $ccy = ($node->getElementsByTagName("Symbol")->item(0)->nodeValue);
    print $ccy;
    $type = ($node->getElementsByTagName("BuySell")->item(0)->nodeValue);
    $lots = ($node->getElementsByTagName("ContractValue")->item(0)->nodeValue);
    $price = ($node->getElementsByTagName("Price")->item(0)->nodeValue);
    $confnumber = ($node->getElementsByTagName("ConfirmationNumber")->item(0)->nodeValue);
    $status = ($node->getElementsByTagName("Status")->item(0)->nodeValue);
    $ltid = ($node->getElementsByTagName("lTID")->item(0)->nodeValue);
    $time = ($node->getElementsByTagName("TradeDate")->item(0)->nodeValue);

}

But nothing is getting printed. except the dummy statement. using $res = $xpath->query("/string/NewDataSet/DealBlotter"); did not help. Also a print_r($res); gives output as DOMNodeList obect.

Ayrıca bu Doing şey yazmaz

$objDOM = new DOMDocument(); 
$objDOM->load($result);
$note = $objDOM->getElementsByTagName("DealBlotter");
foreach( $note as $value )
{       
    print "hello";  
    $tasks = $value->getElementsByTagName("Symbol");
    $task  = (string)$tasks->item(0)->nodeValue;

    $details = $value->getElementsByTagName("Status");
    $detail  = (string)$details->item(0)->nodeValue;

    print "$task :: $detail <br>"; 
}

0 Cevap