User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Graphics and Multimedia section within the Web Development category of DaniWeb, a massive community of 391,998 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,175 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Graphics and Multimedia advertiser:
Views: 3094 | Replies: 5
Reply
Join Date: Jan 2006
Posts: 3
Reputation: ignitrix is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ignitrix ignitrix is offline Offline
Newbie Poster

Flash & XML: skipping past 2nd XML Declaration

  #1  
Jan 11th, 2006
I'm using Flash 8 Pro to parse a Microsoft Excel file saved as XML. Excel 2002 had only the standard XML Declaration line:
[PHP]<?xml version="1.0"?>
<Workbook ...>...</Workbook>[/PHP]
However, Excel 2003 now has two XML Declaration lines:
[PHP]<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook ...><...</Workbook>[/PHP]
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:
[PHP]var xmlValML = new XML();
xmlVal.ignoreWhite = true;
xmlVal.load("myFile.xml");
xmlVal.onLoad = function(bSuccess:Boolean):Void {
if (bSuccess) {
var xmlWorkbookMLNode = xmlVal.firstChild;
while (xmlWorkbook.nodeName != "Workbook")
xmlWorkbook = xmlWorkbook.nextSibling;
}
}[/PHP]
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,142
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 10
Solved Threads: 258
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Flash & XML: skipping past 2nd XML Declaration

  #2  
Jan 13th, 2006
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
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Jan 2006
Posts: 3
Reputation: ignitrix is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ignitrix ignitrix is offline Offline
Newbie Poster

Re: Flash & XML: skipping past 2nd XML Declaration

  #3  
Jan 13th, 2006
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.
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,142
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 10
Solved Threads: 258
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Flash & XML: skipping past 2nd XML Declaration

  #4  
Jan 13th, 2006
Originally Posted by ignitrix
[PHP]var xmlValML = new XML();
xmlVal.ignoreWhite = true;
xmlVal.load("myFile.xml");
xmlVal.onLoad = function(bSuccess:Boolean):Void {
if (bSuccess) {
var xmlWorkbookMLNode = xmlVal.firstChild;
while (xmlWorkbook.nodeName != "Workbook")
xmlWorkbook = xmlWorkbook.nextSibling;
}
}[/PHP]

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
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Jan 2006
Posts: 3
Reputation: ignitrix is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ignitrix ignitrix is offline Offline
Newbie Poster

Re: Flash & XML: skipping past 2nd XML Declaration

  #5  
Jan 13th, 2006
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
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,142
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 10
Solved Threads: 258
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Flash & XML: skipping past 2nd XML Declaration

  #6  
Jan 14th, 2006
Good, that is what I was trying say to you
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Graphics and Multimedia Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Graphics and Multimedia Forum

All times are GMT -4. The time now is 10:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC