xml格式不太方便
TypeId和Slot可以放在属性里也就是getElementsByTagName,firstChild,nextSibling,parentNode,children
几个方法套用一下

解决方案 »

  1.   

    2.xml
    <?xml version="1.0" encoding="utf-8"?>
    <ShipSlotInfo> 
      <SlotType> 
        <TypeId>143101</TypeId>
        
        <ShipSlot> 
        <Slot>0</Slot> 
        <AssemblyTypeId>111111 </AssemblyTypeId> 
        <AssemblyTypeId>222222 </AssemblyTypeId> 
        </ShipSlot> 
        
        <ShipSlot> 
          <Slot>1</Slot> 
          <AssemblyTypeId>333333</AssemblyTypeId> 
          <AssemblyTypeId>44444</AssemblyTypeId> 
        </ShipSlot> 
        
      </SlotType> 
    </ShipSlotInfo> <html>
    <head>
    <script>
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); 
    xmlDoc.load("2.xml");
    var str = getByVal("143101","0");
    alert(str);//111111,222222
    function getByVal(TypeId,Slot)
    {
        var typeId=xmlDoc.selectSingleNode("ShipSlotInfo/SlotType/TypeId[text()='"+TypeId+"']");
        if(typeId!=null)
        {
            var slot = typeId.parentNode.selectSingleNode("ShipSlot/Slot[text()='"+Slot+"']");
            if(slot!=null)
            {
               var asm = slot.parentNode.getElementsByTagName("AssemblyTypeId");
               var arr = [];
               for(var i=0;i<asm.length;i++)
               {
                    arr.push(asm[i].text);
               }
               return arr.join(",");
            }
        }
        return "";
    }
    </script>
    </head>
    <body></body>
    </html>
      

  2.   

    主要就是xpath语法,多看看就知道了
      

  3.   

    多谢CutBug的帮助,非常感谢!我该认真看看书了