<person>
<firstname>
<lastname>
<salary>
</person>
これは解析しているXMLです。私は人、 の子要素のノード名を印刷しようとすると私はの#textをなくすにはどうすればよいXMLノードのgetNodeName()オペレーションは#textを返します
テキストfirstnameの
テキスト姓
テキスト給与
を取得します生成されますか?
アップデート - あなたはsetValidating(true)
を使用する場合はここで は私のコードは
try {
NodeList nl = null;
int l, i = 0;
File fXmlFile = new File("file.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
dbFactory.setValidating(false);
dbFactory.setIgnoringElementContentWhitespace(true);
dbFactory.setNamespaceAware(true);
dbFactory.setIgnoringComments(true);
dbFactory.setCoalescing(true);
InputStream in;
in = new FileInputStream(fXmlFile);
Document doc = dBuilder.parse(in);
doc.getDocumentElement().normalize();
Node n = doc.getDocumentElement();
System.out.println(dbFactory.isIgnoringElementContentWhitespace());
System.out.println(n);
if (n != null && n.hasChildNodes()) {
nl = n.getChildNodes();
for (i = 0; i < nl.getLength(); i++) {
System.out.println(nl.item(i).getNodeName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
コードを表示する。 – swemon
コードが提供されています。助けてください – coder