I'm using Flash 8 Pro to parse a Microsoft Excel file saved as XML. Excel 2002 had only the standard XML Declaration line:

<?xml version="1.0"?>
<Workbook ...>...</Workbook>

However, Excel 2003 now has two XML Declaration lines:

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook ...><...</Workbook>

Everything works fine if I delete the 2nd XML Declaration line, but I'm hoping to not require this of my users whenever they save a new Excel file as XML. I tried the following code w/out success:

var xmlVal:XML = new XML();
xmlVal.ignoreWhite = true;
xmlVal.load("myFile.xml");
xmlVal.onLoad = function(bSuccess:Boolean):Void {
    if (bSuccess) {
        var xmlWorkbook:XMLNode = xmlVal.firstChild;
        while (xmlWorkbook.nodeName != "Workbook")
        xmlWorkbook = xmlWorkbook.nextSibling;
    }
}

The problem is that "xmlVal.firstChild" points to "undefined" if the 2nd XML Declaration line exists. Any help would be greatly appreciated...

Thanks ahead of time.

~Nate

I'm not in Flash programming, but principle is gone be same for all programming. Try to search for first association of "Workbook" and read from that point on or assume that this work on principle read line-by-line do an if statement to check for read content if that is
<?mso-application progid="Excel.Sheet"?>
than ignor it and read next line

Thanks Peter. The while loop at the end code block of my original post did exactly that. The problem is that "xmlVal.firstChild" == undefined. In other words, it's as if I didn't even load any XML at all--I have no access to any nodes to even check what they node name is. :(

var xmlVal:XML = new XML();
xmlVal.ignoreWhite = true;
xmlVal.load("myFile.xml");
xmlVal.onLoad = function(bSuccess:Boolean):Void {
    if (bSuccess) {
        var xmlWorkbook:XMLNode = xmlVal.firstChild;
        while (xmlWorkbook.nodeName != "Workbook")
        xmlWorkbook = xmlWorkbook.nextSibling;
    }
}

If you don't mind, can you explain line-by-line what you are doing?
What I understand/gues is
1)declaring variable to hold xml
2)you ignore white space
3)loading in xml file
4)checking if document loaded properly
5) if yes continue with
a)assign value of xmlVal.firstChild to var on other side {what is firstChild any declaration/description?}
b)while you do not find Workbook repeat { does it already passed first workbook?}
c)asuming this is reading part - reading from xml

I figured out the solution to my problem (thanks astgtciv). I basically just run a cleanup script to remove the bad DTD line before parsing. The following code will do this:

XML myxml = new XML();
myxml.onData = function (src:String) {
    if (src == undefined) {
        this.onLoad(false);
    } else {
        src = cleanUp(src);
        this.parseXML(src);
        this.loaded = true;
        this.onLoad(true);
    }
}
function cleanUp(src:String):String {
    var sStringToRmv:String = "<?mso-application progid=\"Excel.Sheet\"?>";
    var nBadStrLoc:Number = src.indexOf(sStringToRmv, 0);
    if (nStrLoc >= 0)
        src = src.slice(0, nBadStrLoc) + src.slice(nBadStrLoc+sStringToRmv.length, src.length);
    return src;
}

~Nate

Good, that is what I was trying say to you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.