我正在使用Java的DOM解析器來解析XML文件。文檔 - 如何通過名稱獲取標籤的值?
讓我們說我有以下XML
<?xml version="1.0"?>
<config>
<dotcms>
<endPoint>ip</endPoint>
</dotcms>
</config>
</xml>
我想獲得「端點」的值。我可以用下面的代碼片段來做到這一點。 (假設我已經用DocumentBuilder解析了它)
NodeList nodeList = this.doc.getElementByTagName("dotcms");
Node nValue = (Node) nodeList.item(0);
return nValue.getNodeValue();
是否可以通過字段名稱獲取字段的值?像....
Node nValue = nodeList.getByName("endPoint")
這樣的事情...?
//很棒!我很感激!簡短但有用的答案。 – Moon