Copy link to clipboard
Copied
I'm having a problem with loading an XML file that was created by Filemaker. Filemaker will output an XML file using one of two different grammars. One outputs in a mostly standard form that I can use with one glitch. Flash CS4 AS3 seems to have a problem with the xmlns in one of the nodes.
Specifically:
<FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
If I remove the xmlns="http://www.filemaker.com/fmpdsoresult" the file loads properly and I can access the various fields with no problem. However, when I leave the xmlns=... in, it will trace out the XML properly but I can't access the fields using the code listed below. This is driving me crazy!
With the xmlns part in the XML file I get the following error when it tries to load the thumbnail files:
TypeError: Error #1010: A term is undefined and has no properties.
I need to have it so that the user can enter/edit data and simply output the XML file from Filemaker and then Flash will load up the unaltered XML file and show the info requested by the user. That is to say I could have the user open the XML file in a word processing application and have them delete the xmlns..., but that is rather cumbersome and not very user friendly.
I've tried every xml.ignore function I could find but it doesn't help. Hopefully someone out there can help
Thanks,
-Mark-
_____________________________________________________________________________________
Partial XML:
XML From Filemaker Export:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- This grammar has been deprecated - use FMPXMLRESULT instead -->
<FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
<ERRORCODE>0</ERRORCODE>
<DATABASE>Sport.fp7</DATABASE>
<LAYOUT></LAYOUT>
<ROW MODID="1" RECORDID="1">
<FirstName>Mark</FirstName>
<LastName>Fowle</LastName>
<Sport>Sailing</Sport>
<Medal>None</Medal>
<CourseOfStudy>Design</CourseOfStudy>
<Year>1976-1978</Year>
<HomeState>California</HomeState>
<ImageName>93</ImageName>
</ROW>
...
</FMPDSORESULT>
__________________________________________________________________________________
AS3 Code:
import fl.containers.UILoader;
var aPhoto:Array=new Array(ldPhoto_0,ldPhoto_1,ldPhoto_2,ldPhoto_3,ldPhoto_4,ldPhoto_5);
var toSet:int=10;//time out set time
var toTime:int=toSet;
var photoPerPage:int=6;
var fromPos:int=photoPerPage;
var imgNum:Number;
//var subjectURL:URLRequest=new URLRequest("testData_FM8.xml");
var subjectURL:URLRequest=new URLRequest("Sports.xml");
var xmlLoader:URLLoader=new URLLoader(subjectURL);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
var subjectXML:XML = new XML();
subjectXML.ignoreWhitespace=true;
subjectXML.ignoreComments=true;
subjectXML.ignoreProcessingInstructions=true;
function xmlLoaded(evt:Event):void {
subjectXML=XML(xmlLoader.data);
if (root.loaderInfo.bytesTotal==root.loaderInfo.bytesLoaded) {
removeEventListener(Event.ENTER_FRAME, xmlLoaded);
trace("XML Data File Loaded");
trace(subjectXML);
} else {
trace("File not Found");
}
imgNum=2;//subjectXML.ROW.length;
trace(subjectXML);
loadThumb(0);
}
function loadThumb(startPos:int):void {
var count:Number=aPhoto.length;
trace(subjectXML.DATABASE);
for (var i=0; i<count; i++) {
try{
aPhoto.source="images/"+subjectXML.ROW[startPos+i].ImageName+"_main.jpg";
}catch (e:Error){
trace(e);
}
aPhoto.mouseChildren=false;
aPhoto.addEventListener(MouseEvent.MOUSE_DOWN, onThumbClick);
}
trace("Current mem: " + System.totalMemory);
ldAttract.visible=false;
}
function unloadThumb():void {
var count:Number=aPhoto.length;
for (var i=0; i<count; i++) {
aPhoto.unload();
aPhoto.removeEventListener(MouseEvent.MOUSE_DOWN, onThumbClick);
}
trace("Current mem: " + System.totalMemory);
}
function onThumbClick(evt:MouseEvent) {
var i:Number;
//trace("Thumbnail Clicked " + evt.target.name);
i=findPos(evt.target.name);
ldLrgPhoto.source="images/"+subjectXML.ROW[i+fromPos].LOCAL_OBJECT_ID+"_main.jpg";
ldLrgPhoto.visible=true;
btnPrev.visible=false;
btnNext.visible=false;
gotoAndStop("showPhoto");
}
function findPos(thumb:String):Number {
var pos:Number;
var count:Number=aPhoto.length;
for (var i:Number=0; i<count; i++) {
if (thumb==aPhoto.name) {
pos=i;
}
}
return pos;
}
1 Correct answer
Mark,
The '::' is what is called a scope resolution operator. Using a namespace allows you to have potentially two or more nodes that have the same name but a 'different' namespace. These are normally specified in xml as xmlns:mynamespace="http://myuniqueURI.com/etc"
Normally you would use the mynamespace:node in naming your xml nodes that are specific to that namespace.
But the kicker is that the default namespace, where there is no actual namespaceprefix: in the node name like:
<mynamespace:item>
T
...Copy link to clipboard
Copied
Maybe there's an easier solution, but regardless, this should at least get things working:
add in the line to support the namespace (even thought its saying it is the default namespace)
var filemaker:Namespace = new Namespace("http://www.filemaker.com/fmpdsoresult");
then in each of your xml filters, use this name space like so:
subjectXML.filemaker::DATABASE
subjectXML.filemaker::ROW
etc
Copy link to clipboard
Copied
Greg,
Thanks that does seem to work. Seems easy enough!
I'm curious about the two :: after the namespace. I thought it only needed one. Is that filemaker: plus a blank namespace thus another : ?
I'd be interested in any comments about why the code: ImgNum=subjectXML.fm::ROW.length; (I've used fm for the namespace) returns 0 no matter what. Any ideas?
Thanks,
-Mark-
Copy link to clipboard
Copied
Mark,
The '::' is what is called a scope resolution operator. Using a namespace allows you to have potentially two or more nodes that have the same name but a 'different' namespace. These are normally specified in xml as xmlns:mynamespace="http://myuniqueURI.com/etc"
Normally you would use the mynamespace:node in naming your xml nodes that are specific to that namespace.
But the kicker is that the default namespace, where there is no actual namespaceprefix: in the node name like:
<mynamespace:item>
That's how it is specifed in your xml, ie all nodes without a prefix belong to the filemaker namespace.
In actionscript you access it using the scope resolution operator and the variable which represents the namespace does not necessarily look like the 'mynamespace' part above. In your case the namespace being used was the default one (no prefixes), but was assigned a value.
For the length question, you need to use the length() method, otherwise the e4x filtering is looking for nodes named 'length' and creating an XMLList with no entries in it (because there are none). This is a common thing with other 'properties' that are expressed as methods...such as children() and often caught me out when I started with the as3 XML model.
Copy link to clipboard
Copied
Greg,
Thanks you've been a great help and have restored my sanity!
-Mark-

Copy link to clipboard
Copied
Hi,
I was trying to use xml namespaces, so in my application I receive an XML file from the server. The file has a namespace, so when I parse the file I need to specify the namespace:
I got the following piece of xml:
<ls:exchange xmlns:ls=".../tsw" xmlns:tm="http://kxa">
<ls:projects>
<tm:annotation id="" date="" action="getprojects" status="responseok"/>
<ls:project id="" name="proj" description="..." owner="asss" release="2" />
<ls:projectV id="" version="" creationdate="" modificationdate=""/ >
</ls:project>
</ls:projects>
</ls:exchange>
and the following code
<mx:VBox label="WELCOME" verticalScrollPolicy="off" horizontalScrollPolicy="off">
<mx:Tree id="tree" dataProvider="{srv.lastResult.project}" labelField="@name" width="300" height="100%" itemOpen="itemOpenEvt(event);" />
</mx:VBox>
So i want to display the content of the xml (project nodes”) in a tree view, but i don’t know how to includes the namespace"ls:" in the data provider “srv.lastResult.project”. can u help me it’s urgent.
sincerly
Celine

Copy link to clipboard
Copied
Start a new thread. This one is answered.

