Page 1 of 1

DOM Object Help

Posted: Mon Mar 26, 2012 9:40 am
by gotornot
I am trying to get elements in a dom object to display and manipulate however i cant seem to get them all out:

This is the feed:
<TransactionList>
<TransactionID>507821041</TransactionID>
<TransactionDate>2012-03-12T13:23:00+00:00</TransactionDate>
<MerchantID>547</MerchantID>
<MerchantName>The High Street Web</MerchantName>
<ProgrammeID>1865</ProgrammeID>
<ProgrammeName>THE HIGHSTREET WEB</ProgrammeName>
<TrackingReference>{CLICKID}</TrackingReference>
<IPAddress>82.34.245.167 </IPAddress>
<SaleValue>0.0000</SaleValue>
<SaleCommission>0.0400</SaleCommission> <LeadCommission>0.0000</LeadCommission>
</TransactionList>

However i am trying to get more than 1 tag but i cant seem to get it right.
This is my code:

<?php

$dom = new DomDocument;
$dom -> load ( "http://xyz.com" );
$tracking = $dom -> getElementsByTagName( "TrackingReference" );
//$com = $dom -> getElementsByTagName( "SaleCommission" );
$c1 = 0;
foreach( $tracking as $code )
{
#echo $code -> textContent.'<br>';
$tcode = $code -> textContent;
$tcom = $com -> textContent;
//$com = $dom -> getElementsByTagName( "SaleCommission" );
if ($tcode !="")
{
$remove_it = '{CLICKID}';
$tcode = str_replace($remove_it, "", $tcode);
echo $tcode.' VALUE '. $com .'<br>';
$c1 ++;
}
}
echo 'Total Count: '.$c1;
?>

Please can someone help and tell me where im going wrong!

Re: DOM Object Help

Posted: Mon Mar 26, 2012 12:07 pm
by califdon
Your feed is formatted as XML. I'm not skilled at XML, but that's what you should be looking for. Try googling 'PHP XML'.

Re: DOM Object Help

Posted: Mon Mar 26, 2012 12:23 pm
by gotornot
i tried that but not got much help.

Re: DOM Object Help

Posted: Mon Mar 26, 2012 12:37 pm
by califdon
My point is that your entire question is about XML, not DOM, but you don't mention that in your Subject or in your post. You need to.

Re: DOM Object Help

Posted: Mon Mar 26, 2012 12:47 pm
by Celauran
Wouldn't it make more sense to use SimpleXMLElement here?

Re: DOM Object Help

Posted: Mon Mar 26, 2012 4:30 pm
by social_experiment
gotornot wrote:However i am trying to get more than 1 tag but i cant seem to get it right.
Do you want to 'get' the whole document?
Edit

Code: Select all

<?php
$doc = new DOMDocument();
$doc->load('book.xml');
echo $doc->saveXML();
?> 
This will display all values from the document