dongliuzi3410 2009-06-03 06: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-03 06: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条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算