views:

38

answers:

1

Hey all,

Can anyone see whats wrong with either the code to grab the XML or the XML file itself? It looks well formed to me and I don't see the cause of the error:

A TypeError has occured: TypeError: Error #1088: The markup in the document following the root element must be well-formed.

    var file:String = 'config.xml';
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest(file);
    loader.load(request);
    loader.addEventListener("complete", onComplete);
    loader.addEventListener("ioError", onIOError);

    private function onIOError(event:Event):void 
    {
        trace("IOERROR (maybe XML file does not exit or have an incorrect name)");
    }

    private function onComplete(event:Event):void 
    {
        var loader:URLLoader = event.target as URLLoader;
        if (loader != null) {
            try {
                var settings:XML = new XML(loader.data);
            } catch (e:TypeError) {
                trace("A TypeError has occured: \r\t" + e);
            }

        } else {
            trace("Loader is not a URLLoader!");
        }
    }

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings>
    <setting1>1</setting1>
    <showDebug>2</showDebug>
    <someOtherSetting>3</someOtherSetting>
</settings>
+2  A: 

What did you create the XML document in?

I had something similar occur the other day, depending on the text/xml editor it may add a Byte Order Mark to the beginning Wikipedia BOM . This instantly invalidates the XML file. Try copying and pasting what you have into notepad and re-saving it.

Or, if you have a Linux machine available, the BOM will appear in VI as '' and you can remove it.

Also, just for reference, the utf encoding for the BOM is '\ufeff'

Freddy
Window's Notepad... I've also been editing directly in Eclipse. Ill try what you suggest
Even though I thought I tried this previously, creating a new file with the same info in vim did the trick. Thanks!