各位:我想用Javascript查询XML里面的数据,根据几个条件来进行组合查询,如查询某个时间时间段之内标题TITLE包含JACK的单词.
 xmlReportData.setProperty('SelectionLanguage','XPath');
 var node  =  xmlReportData.documentElement.selectNodes("//root/document[contains(title,'JACK')>0 and doc_date>='" + id +"' and doc_date<='" + id1 +"']");   这样查询总是查不到数据
如果如下这样单独查询就没有问题
1) xmlReportData.setProperty('SelectionLanguage','XPath');
 var node  =  xmlReportData.documentElement.selectNodes("//root/document[contains(title,'JACK')]");   
2)
 var node  =  xmlReportData.documentElement.selectNodes("//root/document[doc_date>='" + id +"' and doc_date<='" + id1 +"']");  
不知道是何故?谁能帮我解答一下?

解决方案 »

  1.   

    贴一下你的xml内容是什么  
      

  2.   

    看下这个http://blog.csdn.net/oxcow/archive/2010/06/06/5651244.aspx
    里面有详细的实现
      

  3.   

    这是我的XML结构!
    <?xml version="1.0" ?>
    <root>
    <document id="1">
    <cabinet>09. SWD</cabinet>
    <folder>to HIPHING</folder>
    <title>Reply to CVI</title>
    <ref></ref>
    <doc_type>GEN - General Issues</doc_type>
    <doc_date>2009-05-25</doc_date>
    <issue_ref></issue_ref>
    <our_ref></our_ref>
    <your_ref></your_ref>
    <description></description>
    <from_company>SWD</from_company>
    <to_company>YEARFULL</to_company>
    <our_ref_1></our_ref_1>
    <your_ref_1></your_ref_1>
    <submission_ref></submission_ref>
    <attachment_links></attachment_links>
    <status></status>
    <keywords></keywords>
    <confidential>No</confidential>
    <created_by></created_by>
    <created_on>2009-05-25 04:40:19 PM</created_on>
    <system_no>PIMS/000300</system_no>
    <version>1.0</version>
    <doc_size>1.4 MB</doc_size>
    <doc_extension>pdf</doc_extension>
    <path>09. SWD/to HIPHING</path>
    <file_name>SKMBT_C55009052516300.pdf</file_name>
    </document></root>
      

  4.   


    var loadXML = function(xmlFile)
    {
        var xmlDoc;
        if(window.ActiveXObject)
        {
            xmlDoc    = new ActiveXObject('Microsoft.XMLDOM');
            xmlDoc.async    = false;
            xmlDoc.load(xmlFile);
        }
        else if (document.implementation&&document.implementation.createDocument)
        {
            xmlDoc    = document.implementation.createDocument('', '', null);
            xmlDoc.load(xmlFile);
        }
        else
        {
            return null;
        }    
        return xmlDoc;
    }var initializeSelect    = function(xPath)
    {
        var xmlDoc    = loadXML('/EBS/XML/Login.xml');
        var n;
        var l;
        if(e!=null)
        {
            n    = xmlDoc.getElementsByTagName(xPath);
           alert(n[0].childNodes);//操作node节点       
        }
    }
      

  5.   

    总共有三篇 从js读取xml开始,到使用xpath。上面有例子可以下下来自己跑跑。文档w3c上就有。学会看文档。
      

  6.   

    你好,我需要进行查询才行,因为数据可能会比较大,在你的列子中,XPATH,怎么传递变量我也不是很清楚,能否再仔细一些?
      

  7.   

    用jquery中的$.get请求xml文件,然后返回xml对象,然后根据这个xml对象进行遍历查找就可以了吧,大概应该用到xpath表达式吧
      

  8.   


    我看了这几偏文章,但还是不明白,因为没有对日期的操作比较,是不是XPATH,对日期格式不支持还是什么原因?
    另外这个列子好象还不能下载,所以也就无法看到运行的结果!