DOM Object Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gotornot
Forum Commoner
Posts: 54
Joined: Fri Jul 31, 2009 2:30 am

DOM Object Help

Post 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!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: DOM Object Help

Post 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'.
gotornot
Forum Commoner
Posts: 54
Joined: Fri Jul 31, 2009 2:30 am

Re: DOM Object Help

Post by gotornot »

i tried that but not got much help.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: DOM Object Help

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: DOM Object Help

Post by Celauran »

Wouldn't it make more sense to use SimpleXMLElement here?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: DOM Object Help

Post 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
“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
Post Reply