我有一个如下的 XML:
<parent>
<child1>
</child1>
<child2>
</child2>
</parent>
<parent>
<child3>
</child3>
<child4>
</child4>
</parent>
我能够使用以下代码读取第一个父节点的子节点值:
// Get the staff element by tag name directly
Node PatientVariables = doc.getElementsByTagName("parent").item(0);
// loop the staff child node
NodeList patientlist = PatientVariables.getChildNodes();
for (int i = 0; i < patientlist.getLength(); i++) {
Node node = patientlist.item(i);
if ("child1".equals(node.getNodeName())) {
PatientLastNameValue=node.getTextContent();
//System.out.println("The XML value:"+node.getTextContent() );
}
但我无法读取第二个父节点值(child3 和 child4)