我正试图解组XML文件,但标题中出现此错误。我搜索了其他问题,但不确定该怎么办。 我使用Pojo将XML文件转换为Java Object,但是我没有使用任何XML注释。这是我的XML文件:
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>
<friendlyName>dummyvariable</friendlyName>
<manufacturer>dummyvariable</manufacturer>
<manufacturerURL>dummyvariable</manufacturerURL>
<modelDescription>dummyvariable</modelDescription>
<modelName>dummyvariable</modelName>
<modelNumber>dummyvariable</modelNumber>
<modelURL/>
<serialNumber>dummyvariable</serialNumber>
<UDN>dummyvariable</UDN>
<serviceList>
<service>
<serviceType>urn:schemas-dummy-com:service:Dummy:1</serviceType>
<serviceId>urn:dummy-com:serviceId:dummy1</serviceId>
<controlURL>/dummy</controlURL>
<eventSubURL>/dummy</eventSubURL>
<SCPDURL>/dummy.xml</SCPDURL>
</service>
</serviceList>
<presentationURL>dummyvariable</presentationURL>
</device>
</root>
这是我的吸气方法:
public Root getURL(String urrl){
BufferedReader br = null;
try {
URL url = new URL(urrl);
br = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
StringBuilder sb = new StringBuilder();
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
StringReader sr = new StringReader(sb.toString());
JAXBContext jaxbContext = JAXBContext.newInstance(PojoTest.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
PojoTest pojoTest = (PojoTest) unmarshaller.unmarshal(sr);
System.out.println(pojoTest.toString());
return pojoTest.getRoot();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
我有6个pojo类pojoTest返回具有specVersion,device和xmlns变量的Root,而我实际要返回的值是制造商,modelName,modelNumber,serialNumber和presentationURL。