令人沮丧的 XML 错误、Flex 和开放X
我正在尝试让 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 = [email protected]();
_mediaSource = [email protected]();
}
else if (_flash) {
_mediaSource = [email protected]();
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);
不幸的是,我不知道错误是什么。有什么建议吗?我已经准备好接受脑白质切除术了
谢谢。
-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 ('&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>
我仍然没有看到错误。希望有人会看到这个问题。
谢谢。 -拉克斯米迪
I'm trying to get Flex and OpenX to work together.
OpenX is returning XML. I've got two Flex classes that clean-up the XML and place the ads on my site (thank you Daryl Bowden). Unfortunately, I get Error #1090: XML parser failure, when I test it. And I can't figure out why.
The first class is:
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 = [email protected]();
_mediaSource = [email protected]();
}
else if (_flash) {
_mediaSource = [email protected]();
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;
}
}
}
The second class is:
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;
}
}
}
This is the what OpenX returns:
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);
Unfortunately, I can't figure out what the error is. Any suggestions? I'm ready for a lobotomy.
Thank you.
-Laxmidi
/////////////////////
As Antti suggested, I traced adReturn. Please see below:
<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>
I still don't see the error. Hopefully someone will see the problem.
Thank you.
-Laxmidi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在从 adReturn 创建 XML 对象(解析 xml)之前尝试追踪 adReturn。然后通过 XML 解析器运行结果,这很可能会让您清楚地了解问题所在。
Try tracing out adReturn before creating an XML object from it (parsing xml). Then run the result through an XML parser which most likely should give you a good idea of what's wrong.
我没有阅读您的所有代码,但从您的示例输出来看,我认为您的问题是 Flash 需要单个根节点来将某些内容解析为 XML,而您的数据有一大堆。
将它们包装在一个标签中,它应该可以工作。
I didn't read all your code, but judging from your sample output I think your problem is that Flash needs a single root node to parse something as XML, your data has whole bunch of them.
Wrap them in a single tag and it should work.