以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  基于xpath的模糊查询方法  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=19868)


--  作者:zhangdh1005@126.com
--  发布时间:6/24/2005 9:14:00 AM

--  基于xpath的模糊查询方法
以下是一个 简单的示例函数 , 特拿出来共享。

    public int QuerybyByIDXpath(String QueryCond, String Xvalue) {
        String XpathStr = "";

        if (QueryCond.equals("QueryByID")) {
            XpathStr = "//EmployeeList/EmployeeInfo[@ID='" + Xvalue + "']";
        }

        if (QueryCond.equals("QueryByName")) {
            XpathStr = "//EmployeeList/EmployeeInfo[@Name='" + Xvalue + "']";
        }
            //下面这句就是 基于xpath 的模糊查询方法。查询所有子节点内容中包含
            //Xvalue 的EmployeeInfo元素
             
             if (QueryCond.equals("QueryByAddr")) {
            XpathStr = "//EmployeeList/EmployeeInfo[contains(Address,'" +
                Xvalue + "')]";
        }

        try {
            XPath servletPath = XPath.newInstance(XpathStr);
            List res = servletPath.selectNodes(doc);
            count = res.size();

            for (int j = 0; j < res.size(); j++) {
                Results.add(new userInfoEntity((Element) res.get(j)));
            }
        } catch (Exception e) {
            System.out.println("Error! " + e.getMessage());
        }

        return count;
    }


--  作者:ljh423
--  发布时间:3/25/2006 9:27:00 AM

--  
要导入那些包啊,老报错
--  作者:jomper
--  发布时间:3/25/2006 10:52:00 AM

--  
不算模糊啊...只是可以控制查询属性.
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms