tags:

views:

1589

answers:

2
$output .="<keyword>".$_POST['keyword']."</keyword><name>".$row['url']."</name><occur>".$row['occurrences']."</occur><queryTime>".(substr($end_time-$start_time,0,5))."</queryTime>";
}

I want to check in Flex, if the value of name is null or not. I tried for these, but i am not getting any alert when the node value is empty.

event.result.attribute("name").value < 0

event.result.attribute("name").length < 0

event.result.loginsuccess.name = ""

Can anyone Help me out, Here is my flex code below.

if(keyword.text == "") 
{ 

Alert.show("Please enter the search term");
    } else if(event.result.attribute("name").length < 0) {
      Alert.show("No search Results"); } 
else { 
          subtitle.text = "Search results for " +  event.result.loginsuccess.keyword[0];
            query.text = "query executed in " + event.result.loginsuccess.queryTime[0] + " Seconds";
         }
         }
+1  A: 

check this

event.result.loginsuccess.name[0] == null

why?

because when you call a child directly on XML it always returns as XMLList so we should check that if XMLList has any child. The [0] (first index) tries to return the first child if exists othwerwise returns null

in your example it should be :

if(event.result.name[0])
{
...
}

because the name is an element not attribute, if name was attribute then it should be

if(event.result.@name[0])
{
...
}

i hope it helps

EDIT

pls try this way

if(keyword.text == "") 
{ 

Alert.show("Please enter the search term");
    } else if(!XML(event.result).name[0]) {
                Alert.show("No search Results"); } 
else { 
                        subtitle.text = "Search results for " +  event.result.loginsuccess.keyword[0];
                                        query.text = "query executed in " + event.result.loginsuccess.queryTime[0] + " Seconds";
                }
                }
Tolgahan Albayrak
I am not getting any alert message, when the name field is null... its not checking i think so.
I tried with your code, i get the alert message now but the problem is when there is a result for a particular keyword then also it shows No search results. Its not going to else condition itself.
your xml output is wrong, a xml should have one element (root element). start your output with <root> or any name you want and close the root tag at the end of output
Tolgahan Albayrak
A: 

Can also check for empty string e.g.

if(event.result.name=="")
{
}
Phil C