令人沮丧的XML错误,Flex,& OpenX的

时间:2010-01-26 23:05:41

标签: xml flex openx

我正在努力让Flex和OpenX一起工作。

OpenX正在返回XML。我有两个Flex类来清理XML并将广告放在我的网站上(谢谢Daryl Bowden)。不幸的是,当我测试它时,我得到错误#1090:XML解析器失败。我无法弄清楚原因。

第一堂课是:

package com.darylbowden.ads
{
 import mx.controls.Alert;

 public class Ad extends Object {
  private var _clickURL:String;
  private var _mediaSource:String;
  private var _target:String;
  private var _flash:Boolean;

  public function Ad(xhtml:XML, flash:Boolean = false) {
   super();
   _flash = flash;
   _parse(xhtml);
  }

  private function _parse(xhtml:XML):void {
   if(!_flash) {
    _clickURL = xhtml.a.@href.toString();
    _mediaSource = xhtml.a.img.@src.toString();
   }
   else if (_flash) {
    _mediaSource = xhtml.div.embed.@src.toString();

    var clickIndex:uint = _mediaSource.indexOf('clickTAG=', 0);
    _clickURL = _mediaSource.substring( clickIndex+9, _mediaSource.length);
   }
  }
  public function get clickURL():String {
   return _clickURL;

  }

  public function get mediaSource():String {
   return _mediaSource;
  }

  public function get target():String {
   return _target;
  }

 }




}

第二节课是:

package com.darylbowden.ads
{
  import flash.external.ExternalInterface;
  import mx.controls.Alert;

 public class OpenAds {

   private static var externalCallback:String = "callOpenAds";
   private static var retries:uint = 10;

   public function OpenAds(){ 
   }

   public function getAdReturn():Ad {
    var xmlReturn:XML;
    if(ExternalInterface.available) {
     var adReturn:String = ExternalInterface.call(externalCallback);

       try

       {
       adReturn = adReturn.replace("//]]>->","//]]>->\n");
       var infoTagsIndex:int = adReturn.indexOf('<script type="text/javascript" src=""', 0);
       adReturn = adReturn.substring(infoTagsIndex, adReturn.length);
       var wasFlash:Boolean = false;
        if(adReturn.search("<embed") == -1) {
         adReturn = adReturn.replace('></a>', '></img></a>');
         adReturn = adReturn.replace('></div>', '></img></div>');
        }
        else {
         adReturn = adReturn.replace('></div>\n<script','></embed></div>\n<script');
         adReturn = adReturn.replace('></div>\n<noscript','></img></div>\n<noscript');
         wasFlash = true;
        }

      adReturn = '<adXMLReturn>' + adReturn + '</adXMLReturn>';
      xmlReturn = new XML(adReturn);

      var ad:Ad;

        if(wasFlash){
         ad = new Ad(xmlReturn, true);
        }
        else {
         ad = new Ad(xmlReturn);
        }
      }
      catch(error:Error){
       Alert.show(error.message + 'stacktrace: ' + error.getStackTrace(), "Error"); 
      }
    }
     else {
     Alert.show("Javascript must be enabled to view this page properly.", "Javascript Not Detected");
     xmlReturn = new XML('<root>xml</root>');
    } 
     return ad; 
    }

 } 



}

这是OpenX返回的内容:

var OX_28140bee = '';
OX_28140bee += "<"+"a href=\'http://www.dcscore.com/openx/www/delivery/ck.php?oaparams=2__bannerid=1__zoneid=4__cb=42492045be__oadest=http%3A%2F%2Fwww.joeblow.com\' target=\'_blank\'><"+"img src=\'http://www.joeblow.com/openx/www/delivery/ai.php?filename=mybanner.png&contenttype=png\' width=\'468\' height=\'60\' alt=\'\' title=\'\' border=\'0\' /><"+"/a><"+"div id=\'beacon_42492045be\' style=\'position: absolute; left: 0px; top: 0px; visibility: hidden;\'><"+"img src=\'http://www.joeblow.com/openx/www/delivery/lg.php?bannerid=1&amp;campaignid=1&amp;zoneid=4&amp;loc=http%3A%2F%2Fwww.dcscore.com%2F&amp;cb=42492045be\' width=\'0\' height=\'0\' alt=\'\' style=\'width: 0px; height: 0px;\' /><"+"/div>\n";
document.write(OX_28140bee);

不幸的是,我无法弄清楚错误是什么。有什么建议?我已准备好进行切除术。

谢谢。

-Laxmidi

/////////////////////

正如Antti建议的那样,我追踪了adReturn。请参阅以下内容:

<script type="text/javascript"><!--//<![CDATA[
   var m3_u = (location.protocol=='https:'?'https://www.dcscore.com/openx/www/delivery/ajs.php':'http://www.dcscore.com/openx/www/delivery/ajs.php');
   var m3_r = Math.floor(Math.random()*99999999999);
   if (!document.MAX_used) document.MAX_used = ',';
   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
   document.write ("?zoneid=4");
   document.write ('&amp;cb=' + m3_r);
   if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
   document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
   document.write ("&amp;loc=" + escape(window.location));
   if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
   if (document.context) document.write ("&context=" + escape(document.context));
   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
   document.write ("'><\/scr"+"ipt>");
//]]>--></script><script type="text/javascript" src="http://www.dcscore.com/openx/www/delivery/ajs.php?zoneid=4&amp;cb=46672151726&amp;charset=UTF-8&amp;loc=http%3A//www.dcscore.com/"></script><a href="http://www.dcscore.com/openx/www/delivery/ck.php?oaparams=2__bannerid=1__zoneid=4__cb=5f5d8fcb97__oadest=http%3A%2F%2Fwww.dcscore.com" target="_blank"><img src="http://www.dcscore.com/openx/www/delivery/ai.php?filename=mybanner.png&amp;contenttype=png" width="468" height="60" alt="" title="" border="0"></a><div id="beacon_5f5d8fcb97" style="position: absolute; left: 0px; top: 0px; visibility: hidden;"><img src="http://www.dcscore.com/openx/www/delivery/lg.php?bannerid=1&amp;campaignid=1&amp;zoneid=4&amp;loc=http%3A%2F%2Fwww.dcscore.com%2F&amp;cb=5f5d8fcb97" width="0" height="0" alt="" style="width: 0px; height: 0px;"></div>
<noscript></noscript>

我仍然没有看到错误。希望有人会看到问题。

谢谢。 -Laxmidi

2 个答案:

答案 0 :(得分:0)

在从中创建XML对象(解析xml)之前尝试遍历adReturn。然后通过XML解析器运行结果,这很可能会让你很好地了解错误。

答案 1 :(得分:0)

我没有阅读你的所有代码,但从你的示例输出判断我认为你的问题是Flash需要一个根节点来解析XML的东西,你的数据有很多。 将它们包装在一个标签中,它应该可以工作。