我想獲得一個XML節點實例的屬性的屬性:獲取DOM節點
<Car name="Test">
</Car>
我要搶車節點的名稱屬性。
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(configFile);
doc.getDocumentElement().normalize();
NodeList layerConfigList = doc.getElementsByTagName("CAR");
Node node = layerConfigList.item(0);
// get the name attribute out of the node.
這是我卡住,因爲這看起來像我可以使用的唯一方法是的getAttributes()與回報的NamedNodeMap和林不知道如何從解壓縮。
謝謝!它工作完美。 – MBU 2011-05-05 09:28:59
我們如何才能通過名稱獲得價值。如果我只想要car1?例如 –
Taran
2016-04-01 21:26:22