Flash & XML: skipping past 2nd XML Declaration

Reply

Join Date: Jan 2006
Posts: 3
Reputation: ignitrix is an unknown quantity at this point 
Solved Threads: 0
ignitrix ignitrix is offline Offline
Newbie Poster

Flash & XML: skipping past 2nd XML Declaration

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,191
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 484
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

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

 
0
  #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)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 3
Reputation: ignitrix is an unknown quantity at this point 
Solved Threads: 0
ignitrix ignitrix is offline Offline
Newbie Poster

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

 
0
  #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 Quick reply to this message  
Join Date: Dec 2004
Posts: 4,191
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 484
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

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

 
0
  #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)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 3
Reputation: ignitrix is an unknown quantity at this point 
Solved Threads: 0
ignitrix ignitrix is offline Offline
Newbie Poster

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

 
0
  #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:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. XML myxml = new XML();
  2. myxml.onData = function (src:String) {
  3. if (src == undefined) {
  4. this.onLoad(false);
  5. } else {
  6. src = cleanUp(src);
  7. this.parseXML(src);
  8. this.loaded = true;
  9. this.onLoad(true);
  10. }
  11. }
  12. function cleanUp(src:String):String {
  13. var sStringToRmv:String = "<?mso-application progid=\"Excel.Sheet\"?>";
  14. var nBadStrLoc:Number = src.indexOf(sStringToRmv, 0);
  15. if (nStrLoc >= 0)
  16. src = src.slice(0, nBadStrLoc) + src.slice(nBadStrLoc+sStringToRmv.length, src.length);
  17. return src;
  18. }

~Nate
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,191
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 484
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

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

 
0
  #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)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Graphics and Multimedia Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC