0
在我的代碼中已經實現了落葉落葉草,我需要解析我放在main()中的xml文件。Java解析XML文件丟失
的Main()
case "XML":
text.append("Processing file type XML: "+files[i].getCanonicalPath() + "\n");
ReadXml read_xml = new ReadXml();
read_xml.read(files[i].getCanonicalPath(), text);
break;
ReadXml.java
public class ReadXml {
ProgramDocument programDocument = new ProgramDocument();
public void read(String FILE, javax.swing.JTextArea text) {
try {
JAXBContext context = JAXBContext.newInstance(ProgramDocument.class);
Unmarshaller u = context.createUnmarshaller();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(FILE);
Object o = u.unmarshal(doc);
doc.getDocumentElement().normalize();
text.append("Account : " +doc.getElementsByTagName("Account").item(0));
}
catch(Exception e) {
text.append("XML file not parsed correctly.\n");
}
}
}
我無法打印任何東西,當我,我看 「空」,或只是空行或某些路徑@號碼
我不是開發人員,我只需要嘗試打開一個XML發送內容到數據庫,但這是已經太遠了。
EDIT:XML
<?xml version="1.0" encoding="UTF-8"?>
<ARRCD Version="48885" Release="38">
<Identification v="ORCOZIO"/>
<Version v="013"/>
<Account v="OCTO">
<Type v="MAJO"/>
<Date v="2016-05-14"/>
</AARCD>
幫助了我很多!謝謝! – Nihvel