<element>
<slot name="slot1">
<port status="active"/>
<port status="inactive"/>
</slot>
<slot name="slot2">
<port status="active"/>
</slot>
</element>
NodeList listOfElement = doc.getElementsByTagName("port");
这给出了xml文件中端口的总数。在特定节点下计算xml节点
我需要找出slot1下有多少个端口。
NodeList listOfShelfs = doc.getElementsByTagName(“shelfs”); \t \t int slot1_count =((Element)(listOfShelfs.item(0)))。getElementsByTagName(“port”)。getLength(); \t \t System.out.println(slot1_count); thnx ... – Andy
System.out.println?这是Java命令,你是不是指'console.log(slot1_count)'或'document.write(slot1_count)' –