Hello, I'm working on my first AIR app and I've run into a bit of a snag. The app is intended to allow users of our system to create a Word document, save it as XML, and then load it into the AIR app and have some manipulation performed to extract data, and finally store the data in a database. The reasons for this app to exist are pretty irrelevant for the particular problem that I'm having, but a little background on my development efforts might help shed light on my situation, and with luck one of you might be able to help me figure this out.
I started on this app using the URLLoader and URLRequest objects to load a Word document saved as XML from a server. This worked fine, I created logic to distinguish between Word 2007 and Word 2003 XML formats and using the E4X XML and XMLList objects I was able to load that XML into an XML object, change it to a string, grab the document body, strip out namespaces and such (formatting is mostly irrelevant here too, only the actual data is of importance) amd eventually get a much simpler XML object or list that contained just the data relevant to the purpose at hand. This was all working fine, I managed to get both Word XML formats to process as I wished and spit out new XML that will serve as the basis for another application that we run. Great!
The problem was that in order to use this method in a distributed way I needed to have the original Word documents accessible to the code, which meant having the user upload their Word file (saved as XML) and then retrieving it with the URLLoader and URLRequest. I actually implemented this method using the FileReference object in AS3 and using some simple PHP code to store the file in a server directory that was accessible to the client. Unfortunately, this lead me to thinking about the security issues involved and how allowing PHP to write to a directory would open it to potential malicious attacks, yada yada yada, you all know the issues. So I thought that I might be able to read the file before uploading it in the kind of circular logic that sometimes happens. When I started into the AS3 docs to check on classes to help, I realized that my initial suspicions were correct and that in order to load and read the file locally, I could use AIR, have the user load up their XML file, process it and then send the resulting XML and info to the database directly (eliminating the need to send files to the server AND preventing the need to allow PHP to write to the server in this instance).
So after a bit of reading and testing, I managed to modify my FLA to publish an AIR file, and started debugging. My Word 2007 document worked fine - I create a File object and a FileStream object and they are easily able to access the file the user selects via the File.browseForOpen method. I then run the processing code, which begins by creating an XML object from the data read from the file. What's happening now is that while the Word 2007 document loads and processes without an issue, the Word 2003 document is causing a 1088 error: The markup in the document following the root element must be well-formed.
I don't understand why this is happening since the same document in the same format was able to be loaded into an XML object when I used the URLLoader to grab the file. The only thing I can conclude is that somehow the FileStream.readUTFBytes() method is somehow causing an issue. I am able to trace out what is being read, but the file is lengthy and I haven't completed my analysis to see if and where the changes are occuring.
If anyone has any experience with this type of situation, I'd really appreciate hearing about it. Thanks in advance for any help you can provide.