我现在想构造一个函数,传入二个参数,一个是节点的起始位置,一个是要返回的结点个数,得到一个个结点集。该怎么实现。

解决方案 »

  1.   

    这是一个测试的XML:
      <?xml version="1.0" encoding="UTF-8" ?> 
     <note time="12:03:46">
      <to>Tove</to> 
      <from>Jani</from> 
      <heading>Reminder</heading> 
      <body type="hello">Don't forget me this weekend!</body> 
      </note>
    下面是我的的JS代码,里面使用了POSITION(),但是好象JS中不支持。
    <html>
    <body>
    <script>
    var xmlDoc=new ActiveXObject("microsoft.xmldom")
    xmlDoc.async = false 
    xmlDoc.load("note.xml")
    var sqlstr="//*[position()<=4 and position()>=2]"
    var mynodes=xmlDoc.selectNodes(sqlstr)
    //var mynodes=xmlDoc.selectNodes("(//*)[1]")
    document.write("The node name of the third item in the node list is: ")
    //alert(mynodes.childNodes[lastChild])
    document.write(mynodes.item(0).text)
    //document.write(xmlDoc.documentElement.lastChild.attributes[0].value)
    </script>
    </body>
    </html>各位可以测测。前段时间经常用到XML,经常得到雨中人和思归二位大侠的帮助。这东西放开一段时间,就没印象了。这厢向二位问候了。谢谢大家。