我想读取xml文件(如下所示),但我得到了Execption.你能帮我解决一下我该如何解决这个问题?
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=
"file:///C:/Documents%20and%20Settings/mojalal/Desktop/FirstXSD.xml">
<log>
<property key="firstKey" value="firstValue"></property>
<property key="secoundKey" value="secoundKey"></property>
<property key="thirdKey" value="thirdValue"></property>
</log>
<env>
<property key="firstenv" value="fo"></property>
<property key="123" value="333"></property>
</env>
</config>
Run Code Online (Sandbox Code Playgroud)
这是我想要读取xml文件的代码
public class ReadXMLFilewithJAXB {
private static List<Property> customer;
@SuppressWarnings("unchecked")
public static void main(String[] args) {
try {
File file = new File("c:\\FirstXML.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Log.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
customer = (List<Property>) jaxbUnmarshaller.unmarshal(file);
} catch (JAXBException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
}
最后这是我得到它的异常
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"config"). Expected elements …Run Code Online (Sandbox Code Playgroud)