Confused by Namespace

I’m using Adobe Flash Builder 4 and having trouble reading xml which requires a namespace.

Here is part of the xml…


<?xml version="1.0" encoding="UTF-8"?>

<MPEFile 
    xmlns="http://www.ngc.com/iossp"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.ngc.com/iossp file:///H:/workspace/Iossp/assets/iossp.xsd">

...

</MPEFile>

Here is part of the xsd…

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns="http://www.ngc.com/iossp"
    xmlns:tns="http://www.ngc.com/iossp"
    targetNamespace="http://www.ngc.com/iossp" 
    elementFormDefault="qualified">

...

</xs:schema>

Here is where the program appears to be crashing…

private function doFileOpen():void {
     var stream:FileStream = new FileStream();
     var fileData:String;
     var fileXML:XML;
                 
     stream.open(pendingFile, FileMode.READ);
     fileData = stream.readUTFBytes(stream.bytesAvailable);
     fileXML = XML(fileData);
     stream.close();

     if (fileXML.namespace("") != undefined) {
        default xml namespace = fileXML.namespace("");
     }

     ...

}

The trace from the crash…

TypeError: Error #1010: A term is undefined and has no properties.
    at MPE/timingTreeLabel()[H:\Adobe Flash Builder 4\EP_MPE_16\src\MPE.mxml:723]
    at mx.controls.listClasses::ListBase/itemToLabel()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:4946]
    at mx.controls::Tree/makeListData()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Tree.as:1327]
    at mx.controls::List/makeRowsAndColumns()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\List.as:1411]
    at mx.controls.listClasses::ListBase/makeRowsAndColumnsWithExtraRows()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:1742]
    at mx.controls.listClasses::ListBase/updateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:4386]
    at mx.controls::List/updateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\List.as:1136]
    at mx.controls::Tree/updateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Tree.as:1203]
    at mx.controls.listClasses::ListBase/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\listClasses\ListBase.as:3966]
    at mx.managers::LayoutManager/validateDisplayList()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:663]
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:736]
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]

How we got from timingTreeLabel() to doFileOpen() is a mystery to me. I put a breakpoint on both the if statement and the default xml namespace statement. The program bypasses the if statement and crashes on the default xml namespace. :facepalm:

Here’s timingTreeLabel…

private function timingTreeLabel(obj:Object):String {
     var so:SO;
                
     if (obj is TP)
        return obj.tp;
     else if (obj is MMT)
        return obj.mmt;
     else if (obj is HW)
        return ("HW #" + obj.hw);
     else {
        if (timingSOLabel.text == "SO") {
            return ("SO #" + MSO(obj).so);
        }
        else {
           for each (so in sOs) {
               if (so.so == MSO(obj).so)
                  return (so.ao + " / " + so.cc);
           }
           return("");
       }
    }
}

And the Tree that calls timingTreeLabel…

<mx:Tree id="timingTree"
                    width="336" height="370" left="361" top="29"
                    backgroundAlpha="0"
                    showRoot="true"
                    indentation="93"
                    showDataTips="true"
                    allowMultipleSelection="true"
                    dragEnabled="true" dragMoveEnabled="true" dropEnabled="true"
                    dragEnter="timingTreeDragEnter(event)"
                    dragOver="timingTreeDragOver(event)"
                    dragDrop="timingTreeDragDrop(event)"
                    dragComplete="{timingTree.selectedIndex = -1}"
                    verticalScrollPolicy="on" horizontalScrollPolicy="off"
                    dataProvider="{timingPlans}"
                    dataTipFunction="timingTreeDataTip"
                    labelFunction="timingTreeLabel"
                    toolTip="{hintToolTipsEnabled ? 'Tree of Life' : ''}"
                    keyDown="{switch (event.keyCode) {
                        case Keyboard.DELETE: if (timingTree.selectedIndex != -1) deleteTPConfirm(); break;
                        case Keyboard.ESCAPE: timingTree.selectedIndex = -1;
                    }}"/>

If I remove xmlns=“http://www.ngc.com/iossp” from the xml and remove the default xml namespace from doFileOpen(), the program works. Unfortunately, Eclipse can’t find the xsd in order to validate the xml. If I leave the xmlns=“http://www.ngc.com/iossp” in the xml but don’t attempt to default xml namespace, no data is read from the xml.

My question is how should I deal with the xmlns?

Any help would be appreciated!