打印本文 打印本文 关闭窗口 关闭窗口
XPath中如何比较不同类型的对象
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2067  更新时间:2009/4/23 10:51:18  文章录入:mintao  责任编辑:mintao
{

                if(operand2 is number)convert node1 to number as a new object named newOperand1

                if(operand2 is string)convert node1 to string as a new object named newOperand1

                if(operand2 is boolean)convert node1 to boolean as a new object named newOperand1

                if(compareBasic(newOperand1,operand2,operator))return true

            }

        }

        return false

    }

 

    boolean compareBasic(Object operand1, Object operand2, String operator) throws Exception{

        if (operator is "<=" or "<" or ">=" or ">"){

            convert operand1 and operand2 to number

            compare the two numbers with the operator;

        }else if("=".equals(operator)||"!=".equals(operator)){

            if(at least one object is boolean){convert the other object to boolean}

            if(at least one object is number){convert the other object to number}

            if(at least one object is string){convert the other object to string}

            compare the new two objects with "=" or "!="

        }else{

            throw new Exception("Doesn’t support this operator!");

        }

    }

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口