1.
final JAXBContext context = JAXBContext.newInstance(XlvdDiagram.class);
final Unmarshaller unmarshaller = context.createUnmarshaller();
final FileReader reader = new FileReader(new File(path));
final SAXParserFactory sax = SAXParserFactory.newInstance();
sax.setNamespaceAware(false);// 忽略命名空间
final XMLReader xmlReader = sax.newSAXParser().getXMLReader();
final SAXSource saxSource = new SAXSource(xmlReader, new InputSource(reader));
final Object object = unmarshaller.unmarshal(saxSource);
2
不用时报错
org.xml.sax.SAXParseException; systemId: file:/C:/Users//Desktop/test.xml; lineNumber: 4; columnNumber: 94; 与元素类型 "diagram" 相关联的属性 "xsi:NamespaceSchemaLocation" 的前缀 "xsi" 未绑定。
3