我试图让 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&campaignid=1&zoneid=4&loc=http%3A%2F%2Fwww.dcscore.com%2F&cb=42492045be\' width=\'0\' height=\'0\' alt=\'\' style=\'width: 0px; height: 0px;\' /><"+"/div>\n";
document.write(OX_28140bee);
不幸的是,我无法弄清楚错误是什么。有什么建议么?我已经准备好进行脑叶切除术了。
谢谢你。
-拉克西米迪
///////////////////
正如安蒂建议的那样,我追踪了 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 ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><script type="text/javascript" src="http://www.dcscore.com/openx/www/delivery/ajs.php?zoneid=4&cb=46672151726&charset=UTF-8&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&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&campaignid=1&zoneid=4&loc=http%3A%2F%2Fwww.dcscore.com%2F&cb=5f5d8fcb97" width="0" height="0" alt="" style="width: 0px; height: 0px;"></div>
<noscript></noscript>
我仍然没有看到错误。希望有人会看到这个问题。
谢谢你。-拉克西米迪