Jump to content

Strange XML problem


Gulinborsti
 Share

Recommended Posts

Hi!First of all I have to admit that my knowlegde of XML is very basic. But I studied the tutorials on www.w3schools.com and was able to achieve what I tried to do. But only in theory... :) My problem is:I want to search this XML data for a specific entry ( /server/name ) and display some of the information about this element in an iFrame on my own page.That's the code i tried:

<?xml version="1.0" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>XML Testpage</title><meta http-equiv="Content-Script-Type" content="text/javascript"><meta http-equiv="Content-Style-Type" content="text/css"><style><!--a:link { font-family:Verdana;font-size:10pt;font-weight:bold; color:#FF0000; text-decoration:none }a:visited { font-family:Verdana;font-size:10pt;font-weight:bold; color:#FF0000; text-decoration:none }a:hover { font-family:Verdana;font-size:10pt;font-weight:bold; color:#FFF000; text-decoration:none }a:active { font-family:Verdana;font-size:10pt;font-weight:bold; color:#FF0000; text-decoration:none }a:focus { font-family:Verdana;font-size:10pt;font-weight:bold; color:#FF0000; text-decoration:none }body, p {font-family:Verdana,Arial;font-size:10pt;color:white;line-height:12pt;}.tabtex  {font-family:Verdana,Arial;font-size:9pt;color:white;line-height :12pt;}.title {font-size: 12pt;color:#FFFFFF;font-weight:bold;text-align:center}.hdr {font-size: 12pt;background-color:#DADADA;color:#000000;font-weight:bold;}.row {font-size: 10pt;background-color:#DADADA;color:#000000;}.altrow {font-size: 10pt;background-color:#FFFFFF;color:#000000;}td {font-size: 12px; font-family: Verdana, Tahoma, Arial, Helvetica; color: #FFFFFF;; scrollbar-face-color:}.TD    {background-color: #666666;   color: #FFFFFF;   font-size: 12px; padding-left:5px; padding-right:3px; padding-top:3px; padding-bottom:3px }.menu  { font-family:Verdana,Arial;font-size:8pt;color:black;}--></style><script type="text/javascript">function GetServerData() {  var xmlDoc=new ActiveXObject('Microsoft.XMLDOM');  xmlDoc.async='false';  xmlDoc.load('http://racecast.rfactor.net/rssfeed/RaceCastRSSFeed.xml');    if (xmlDoc.documentElement == null) {    raceEnter.innerHTML='<font color="yellow">XML not found</font>';  } else {    nodes=xmlDoc.documentElement.childNodes;    for ( var i = 0; i < nodes.length; i++ ) {      if ( nodes(i).childNodes(0).text == 'Littlefoot-Race' ) {        raceEvent.innerHTML=nodes(i).childNodes(4).text;        raceSerie.innerHTML=nodes(i).childNodes(5).text;        raceSession.innerHTML=nodes(i).childNodes(6).text;        racePlayer.innerHTML=nodes(i).childNodes(7).getAttribute('number') + ' / ' + nodes(i).childNodes(7).getAttribute('maximum');        raceEnter.innerHTML='<a href="rfactor://' + nodes(i).childNodes(2).text + ':' + nodes(i).childNodes(3).text + ' +password/">Enter server</a>';            break;      }    }    if ( raceEvent.innerHTML == 'unbekannt' ) {      raceEvent.innerHTML='';      raceSerie.innerHTML='';      raceSession.innerHTML='';      racePlayer.innerHTML='';      raceEnter.innerHTML='<font color="yellow">Server offline</font>';    }  }}</script></head><body onload="GetServerData()">    <table border="1" cellspacing="0" cellpadding="0" id="table113">      <tr>        <td bgcolor="#EE4500">          <p align="center"><b><font face="Arial" size="2" color="#000000">KRG-rFactor-Server</font></b></p>        </td>      </tr>      <tr>        <td bgcolor="#3D3D3D" align="center">          <table border="0" width="100%" id="table139" style="border-collapse: collapse" cellspacing="1">            <tr><td>Event </td><td><b><span id=raceEvent>unknown</span></b></td></tr>            <tr><td>Serie </td><td><b><span id=raceSerie>unknown</span></b></td></tr>            <tr><td>Session </td><td><b><span id=raceSession>unknown</span></b></td></tr>            <tr><td>Player </td><td><b><span id=racePlayer>unknown</span></b></td></tr>            <tr><td colspan="2"> </td></tr>            <tr><td align="center" colspan="2"><b><span id=raceEnter>unknown</span></b></td></tr>          </table>        </td>      </tr>    </table></body></html>

Unfortunately this doesn't work and I can't find the reason.I tried it with a local copy of the 'RaceCastRSSFeed.xml' and this failed too:

...var xmlDoc=new ActiveXObject('Microsoft.XMLDOM');xmlDoc.async='false';xmlDoc.load('RaceCastRSSFeed.xml');	if (xmlDoc.documentElement == null) {...

After checking the code millions of times and reading every information about this problem I found, I started to focus on the 'RaceCastRSSFeed.xml' itself. Soon the DTD (lines 2 to 4) seemed a little suspicious to me.

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE RCFEED [<!ENTITY RCFEEDEnt "RaceCast RSS Feed Entity">]><RaceCastRSSFeed>...

So I cut them out of my local copy

<?xml version="1.0" encoding="utf-8"?><!-- <!DOCTYPE RCFEED [<!ENTITY RCFEEDEnt "RaceCast RSS Feed Entity">-->]><RaceCastRSSFeed>...

and - TATA!!!!!! - my code works!!! I loaded only the manipulated XML file up on friends webspace, referenced it in my code and tried it again ... it still worked.Is there a problem with th XMLs DTD???Is this maybe a security problem???I have no influence on the XML file, all I found out by contacting it's author is, that he "believes it to be correct".Any hints and solutions are welcome... :)

Link to comment
Share on other sites

I'm not exactly sure if I understand all of the things you've done, but the way I see it, the DOCTYPE doesn't mach the root element of the document.

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE RCFEED [<!ENTITY RCFEEDEnt "RaceCast RSS Feed Entity">]><RaceCastRSSFeed>...

It should be like this:

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE RaceCastRSSFeed [<!ENTITY RCFEEDEnt "RaceCast RSS Feed Entity">]><RaceCastRSSFeed>...

Because the DTD is not valid, the script does not load the file. If you want to keep the invalid DTD and still load the file, you may always add this to the script:

xml.validateOnParse = false;

Again I say I'm not sure what you have done, and what do you ask for, but still...

Link to comment
Share on other sites

That's exactly what I was wondering... what are you asking for if the code is working? Who cares what went wrong if it works now?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...