Jump to content

Issue With PHP DOM XML?


xxProto

Recommended Posts

Hey everyone, I'm having an issue loading a particular URL with PHP DOMdocument. I'm using this code for a gaming website that is parsing data from an XML file on a separate website. The code works with one XML url, but not the other, so I think it may be something wrong with the server or the XML file itself.

 

This code works and displays correctly:

$team = "Clan DiiE";

$teamurl = "http://gamebattles.com/xbox360/call-of-duty-4/team/clan-diie/stats.xml";

$gbturl = "http://gamebattles.com/xbox360/call-of-duty-4/team/clan-diie";


?>

<?php

$documentx9 = new DOMDocument();
$documentx9->load( $teamurl );

$sites = $documentx9->getElementsByTagName( "player" );
$i=1;  

echo "<h1>$team</h1>";

echo "<img src=images/teaminfo.png border=0 /><p>
<table border=0>
<tr>
<td width=150><b><font size=-2 color=#bfd932 >TAG</b></font></td>
<td><font size=-2>$clantag</font></td>
</tr>
<tr>
<td width=150><b><font size=-2 color=#bfd932 >GAMES</b></font></td>
<td><font size=-2>$activegames</font></td>
</tr>

<tr>
<td width=150><b><font size=-2 color=#bfd932 >ABOUT</b></font></td>
<td><font size=-2>$aboutus</font></td>
</tr>
</table>
</p>

<br />";

echo "<img src=images/teamroster.png border=0 /><p>
<table border=0><tr>
<th><font size=-2 color=#008ebf>Gamertag</font></th>
<th><font size=-2 color=#008ebf>GB Rank</font></th>

<th><font size=-2 color=#008ebf>Title</font></th>

<th><font size=-2 color=#008ebf>Date Joined</font></th>

<th><font size=-2 color=#008ebf>Profile URL</font></th>

</tr>";


foreach( $sites as $site )
{
$nameofsites = $site->getElementsByTagName( "name" );
$name = $nameofsites->item(0)->nodeValue;

$urls = $site->getElementsByTagName( "url" );
$url = $urls->item(0)->nodeValue;

$val1s = $site->getElementsByTagName( "gbRank" );
$val1 = $val1s->item(0)->nodeValue;

$val2s = $site->getElementsByTagName( "url" );
$val2 = $val2s->item(0)->nodeValue;

$val3s = $site->getElementsByTagName( "memberSince" );
$val3 = $val3s->item(0)->nodeValue;
...

 

This one doesn't..


<?php

$team = "Bad Medicine";

$teamurl = "http://gamebattles.com/xbox360/call-of-duty-modern-warfare-2/team/badmedicine/stats.xml";

$gbturl = "http://gamebattles.com/xbox360/call-of-duty-modern-warfare-2/team/badmedicine";

?>

<?php


$documentx9 = new DOMDocument();
$documentx9->load( $teamurl );

$sites = $documentx9->getElementsByTagName( "player" );
$i=1;  

echo "<h1>$team</h1>";

echo "<img src=images/teaminfo.png border=0 /><p>
<table border=0>
<tr>
<td width=150><b><font size=-2 color=#bfd932 >TAG</b></font></td>
<td><font size=-2>$clantag</font></td>
</tr>
<tr>
<td width=150><b><font size=-2 color=#bfd932 >GAMES</b></font></td>
<td><font size=-2>$activegames</font></td>
</tr>

<tr>
<td width=150><b><font size=-2 color=#bfd932 >ABOUT</b></font></td>
<td><font size=-2>$aboutus</font></td>
</tr>
</table>
</p>

<br />";

echo "<img src=images/teamroster.png border=0 /><p>
<table border=0><tr>
<th><font size=-2 color=#008ebf>Gamertag</font></th>
<th><font size=-2 color=#008ebf>GB Rank</font></th>

<th><font size=-2 color=#008ebf>Title</font></th>

<th><font size=-2 color=#008ebf>Date Joined</font></th>

<th><font size=-2 color=#008ebf>Profile URL</font></th>

</tr>";


foreach( $sites as $site )
{
$nameofsites = $site->getElementsByTagName( "name" );
$name = $nameofsites->item(0)->nodeValue;

$urls = $site->getElementsByTagName( "role" );
$url = $urls->item(0)->nodeValue;

$val1s = $site->getElementsByTagName( "gbRank" );
$val1 = $val1s->item(0)->nodeValue;

$val2s = $site->getElementsByTagName( "url" );
$val2 = $val2s->item(0)->nodeValue;

$val3s = $site->getElementsByTagName( "memberSince" );
$val3 = $val3s->item(0)->nodeValue;

 

Any help would be greatly appreciated. Also, I'm somewhat new with PHP, so any tips on tidying up the code or better approaches to coding with XML are welcomed.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/186629-issue-with-php-dom-xml/
Share on other sites

I'm getting this error:

 

 

Warning: DOMDocument::load() [domdocument.load]: Input is not proper UTF-8, indicate encoding ! Bytes: 0x99 0x52 0x69 0x44 in http://gamebattles.com/xbox360/call-of-duty-modern-warfare-2/team/badmedicine/stats.xml, line: 45 in /home/projec55/public_html/test.php on line 33

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.