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!
DOM Object Help
Moderator: General Moderators
Re: DOM Object Help
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
i tried that but not got much help.
Re: DOM Object Help
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
Wouldn't it make more sense to use SimpleXMLElement here?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: DOM Object Help
Do you want to 'get' the whole document?gotornot wrote:However i am trying to get more than 1 tag but i cant seem to get it right.
Edit
Code: Select all
<?php
$doc = new DOMDocument();
$doc->load('book.xml');
echo $doc->saveXML();
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering