【发布时间】:2019-04-30 04:54:17
【问题描述】:
我是新来的,只是想试试能不能在这里得到一些帮助。 我想为我的问题寻求一些帮助。
我有一个 XML 文件,我想将那里的那些字符串与文件扩展名进行比较,例如。 Example.txt -> 将 XML 中的所有字符串与我的文件扩展名进行比较。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href"tx ?>
<zip>
<exclusions>
<switch> .bak </switch>
<switch> .tmp </switch>
<switch> .frm </switch>
<switch> .opt </switch>
<switch> .met </switch>
<switch> .i </switch>
</exclusions>
</zip>
这是我要打印的 XML 代码,我的想法是将所有字符串存储到数组中并将它们与我的扩展名进行比较.. 但我不知道如何。
希望你对我有一些想法。
谢谢
public class xmlFileExten {
public static void main(String[] args) {
try {
File file = new File(xmlFile);
DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = dBuilder.parse(file);
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
if (doc.hasChildNodes()) {
printNote(doc.getChildNodes());
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
private static void printNote(NodeList nodeList) {
for (int count = 0; count < nodeList.getLength(); count++) {
Node tempNode = nodeList.item(count);
if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
System.out.println("Node Value =" + tempNode.getTextContent());
【问题讨论】:
标签: java xml string file compare