dongliuzi3410 2009-06-02 22:23
浏览 16
已采纳

如何在Flex中检查xml值是否为null?

$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";
            }
            }
  • 写回答

2条回答 默认 最新

  • douyan1903 2009-06-02 22:26
    关注

    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";
                    }
                    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部