all groups > flash data integration > december 2004 >
You're in the

flash data integration

group:

Duplicate doc type declaration problem


Duplicate doc type declaration problem MikeKlepper
12/17/2004 6:48:12 PM
flash data integration: Hello,

When reloading XML data into an XML object already containing data, it appears
that the XML object does not totally "clear" itself. For example, when running
this code...

var loadCount:Number = 0;
var myData:String = "myData.xml";
var loadedXML:XML = new XML();

loadedXML.ignoreWhite = true;
loadedXML.onLoad = displayAndTryReload;
loadedXML.load(myData);

function displayAndTryReload(success)
{
if(success)
{
loadCount++;
OutputTxt.text += "Load attempt =
"+loadCount+"\n"+loadedXML.toString()+"\n\n";
if(loadCount<2)
loadedXML.load(myData);
}
else
{
trace("Failed to load!");
}
}

on this XML file...
<?xml version="1.0" encoding="UTF-8"?>
<something></something>

the following output is produced...

Load attempt = 1
<?xml version="1.0" encoding="UTF-8"?><something />

Load attempt = 2
<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0"
encoding="UTF-8"?><something />

A duplicate doc type declaration is produced (and empty paired tags are
converted into a singleton tag).

This can be corrected by changing the code to read...

var loadCount:Number = 0;
var myData:String = "myData.xml";
var loadedXML:XML = new XML();
initLoadedXML();
loadedXML.load(myData);

function initLoadedXML()
{
loadedXML = new XML();
loadedXML.ignoreWhite = true;
loadedXML.onLoad = displayAndTryReload;
}

function displayAndTryReload(success)
{
if(success)
{
loadCount++;
OutputTxt.text += "Load attempt =
"+loadCount+"\n"+loadedXML.toString()+"\n\n";
if(loadCount<2)
{
initLoadedXML()
loadedXML.load(myData);
}
}
else
{
trace("Failed to load!");
}
}


in which case the output is...
Load attempt = 1
<?xml version="1.0" encoding="UTF-8"?><something />

Load attempt = 2
<?xml version="1.0" encoding="UTF-8"?><something />

Explicitly trying to clear the loadedXML object before the second load with
lines like
loadedXML.removeNode(); or
loadedXML.docTypeDecl = null; or
loadedXML.docTypeDecl = "";
doesn't seem to help.

Is this a bug or a feature? Is there an easier way of clearing the XML?

Thanks!
Mike
Re: Duplicate doc type declaration problem Matthew David
12/20/2004 3:52:21 PM
Mike,

You are not alone with this problem. I have run into a lot. Try loading the
data in Internet Explorer and then change over to FireFox or Nestscape. The
problem is the interaction between Player and the Browser. IE likes to cache
data.

What you are doing are good ways to clear data. Yes, I know it feels like
jumping through hoops, but currently, Flash does not support good garbage
collection and disposal as demonsttrate in C++.

One additional trick you can try is force the XML file you are loading to
have a random name each time you load it. OK, I know that sounds crazy, but
try adding a date/time stamp to the end of the XML file. This will force a
new document to be loaded into the cache.


--
Matthew David
PH: 920.475.2972
FAX: 775.239.8171
mdavid@matthewdavid.ws

New Books at http://www.cafepress.com/matthewdavid on Flash Rich Internet
Applications


[quoted text, click to view]

AddThis Social Bookmark Button