tags:

views:

259

answers:

1

Hello!

I'm having a problem retrieving a XMLList and I don't understand why.

I have an application that is running properly. It uses some data from two xml files called division.xml and store.xml. I noticed that I have some data in division.xml that should be in store.xml, so I did a copy/paste of the data from one file to the other. This is the data I copied:

<stores name="Japan" division="C300">   
    <store>
        <odeis>101</odeis>
        <name></name>
        <password></password>
        <currency></currency>
        <currSymbol></currSymbol>
    </store>    
    <store>
        <odeis>102</odeis>
        <name></name>
        <password></password>
        <currency></currency>
        <currSymbol></currSymbol>
    </store>
</stores>

In the application, I list all odeis codes and I need to retrieve the block store corresponding to the selected odeis code.

Before moving the data into store.xml, this is how I retrieved the block:

var node:XMLList = divisionData.division.(@name==HomePageData.instance.divisionName).stores.store.(odeis == HomePageData.instance.storeCodeOdeis)

This is how I retrieve it after copying the data into store.xml:

var node:XMLList = storeData.stores.(@name==HomePageData.instance.divisionName).store.(odeis == HomePageData.instance.storeCodeOdeis)

And I'm currently getting the following error:

ReferenceError: Error #1065: The variable odeis is not defined.

Could anyone enlighten me? Cause I really have no clue of why it is not working...

Thanks for any tips you can give.

Regards, BS_C3


Complete xml structure for division.xml and store.xml

division.xml:

<data>
    <division name="Europe">
    </division>
    <division name="Japan">
        <stores>
            <store> 
                <odeis>101</odeis>
                <name> </name>
                <password></password>
                <currency></currency>
                <currSymbol></currSymbol>
            </store>
            <store>
                <odeis>031</odeis>
                <name></name>
                <password></password>
                <currency></currency>
                <currSymbol></currSymbol>
            </store>
            <store>
                <odeis>032</odeis>
                <name></name>
                <password></password>
                <currency></currency>
                <currSymbol></currSymbol>
            </store>
        </stores> 
        <fingerSize>
            .
            .
            . 
        </fingerSize>
        <clarities> 
            .
            .
            .
        </clarities>
        <colors>
            .
            .
            .
        </colors>
    </division> 
</data>

store.xml:

<data>
    <stores name="Europe" division="C100">
        <store>
            <odeis></odeis>
            <name></name>
            <password></password>
            <currency></currency>
            <currSymbol></currSymbol>
        </store>  
        <store>
            <odeis></odeis>
            <name></name>
            <password></password>
            <currency></currency>
            <currSymbol></currSymbol>
        </store>
        <store>
            <odeis></odeis>
            <name></name>
            <password></password>
            <currency></currency>
            <currSymbol></currSymbol>
        </store> 
    </stores>
    <stores name="Japan" division="C300">   
        <store>
            <odeis>101</odeis>
            <name></name>
            <password></password>
            <currency></currency>
            <currSymbol></currSymbol>
        </store>
        <store>
            <odeis>031</odeis>
            <name></name>
            <password></password>
            <currency></currency>
            <currSymbol></currSymbol>
        </store>
        <store>
            <odeis>032</odeis>
            <name></name>
            <password></password>
            <currency></currency>
            <currSymbol></currSymbol>
        </store>
    </stores>
</data>
+2  A: 

In this line of code :

var node:XMLList = storeData.stores.(@name==HomePageData.instance.divisionName).store.(odeis == HomePageData.instance.storeCodeOdeis)

you are looking for the name attribute of the stores node. Which doesn't appear in your XML example. You are likely filtering all of your results before you even move into the store child node.

If this is not your problem, please post a more robust example of your storeData xml variable.


I copy/pasted and made almost no changes to your E4X query and had no issue. This runs just fine:

<?xml version="1.0"?>
<!-- Simple example to demonstrate the ComboBox control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
    <mx:Script>
        <![CDATA[
            public var storeData:XML = new XML(
                <data>
                    <stores name="Europe" division="C100">
                        <store>
                            <odeis></odeis>
                            <name></name>
                            <password></password>
                            <currency></currency>
                            <currSymbol></currSymbol>
                        </store>  
                        <store>
                            <odeis></odeis>
                            <name></name>
                            <password></password>
                            <currency></currency>
                            <currSymbol></currSymbol>
                        </store>
                        <store>
                            <odeis></odeis>
                            <name></name>
                            <password></password>
                            <currency></currency>
                            <currSymbol></currSymbol>
                        </store> 
                    </stores>
                    <stores name="Japan" division="C300">   
                        <store>
                            <odeis>101</odeis>
                            <name></name>
                            <password></password>
                            <currency></currency>
                            <currSymbol></currSymbol>
                        </store>
                        <store>
                            <odeis>031</odeis>
                            <name></name>
                            <password></password>
                            <currency></currency>
                            <currSymbol></currSymbol>
                        </store>
                        <store>
                            <odeis>032</odeis>
                            <name></name>
                            <password></password>
                            <currency></currency>
                            <currSymbol></currSymbol>
                        </store>
                    </stores>
                </data>
            );

            public function init():void{
                trace(storeData.stores.(@name=="Japan").store.(odeis == "031"));    
            }           

        ]]>
    </mx:Script>
</mx:Application>

As far as I can tell you don't have any problem that should result in that error. Are you sure that the error is coming from there and not some other line of code?

invertedSpear
Oh sorry! I edited the xml... But it's not the issue =)I've reedited the xml.Regards
BS_C3
Hi!I'm pretty sure that the problem comes from this line; when I remove the line, there's no error... The thing that's bothering me is that I don't see any problem either with that line... And that the same line with divisionData.division.(@name=="Japan").stores.store.(odeis=="031") does work!!>_< I even restarted the computer, cleaned the cash, cleaned the project, restarted the server... I really don't know what else to do... -_-'
BS_C3
OK I dug around some more and found this: http://flex.gunua.com/?p=127 it basically says that if the attribute you are filtering on is not in all of the nodes it throws this error. BUT you're not using attributed and odeis is a child in all of your store nodes... maybe this is a bug you can fie with Adobe
invertedSpear
Hi! After restarting Flex Builder and my computer... It just miraculously worked... So there was no error since the beginning but some remaining stuff somewhere in the project... ?? Thanks a lot for your time and your answers invertedSpear.
BS_C3
As my co-worker is fond of saying. Flex Builder is a pathological liar. Sometime you just have to know better :)
invertedSpear