java - 我可以在 javax.xml.bind.MarshalException 上捕获 xml 的行号吗?
问题描述
我还有其他类似的错误,有一种方法可以输出未验证的对象字段?
cvc-enumeration-valid:值 '02' 对于枚举 '[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 不是方面有效的, 16, 17, 18, 19, 20]'。它必须是来自枚举的值。
public static String marshalValidatingBoPgit(Object el) throws Exception {
if (el == null) {
return null;
}
Marshaller m = JaxbContextHolder.getInstance().getMarshaller(XmlObject.class);
m.setSchema(SchemaManager.getSchema("idb/xmlXsd/xml-schema.xsd"));
m.setEventHandler(new ValidationEventHandler() {
public boolean handleEvent(ValidationEvent event) {
System.err.println(event);
return false;
}
});
ByteArrayOutputStream baos = new ByteArrayOutputStream();
m.marshal(el, baos);
baos.flush();
String result = new String(baos.toByteArray());
baos.close();
return result;
}
解决方案
推荐阅读
- r - 根据存储在列中的值创建新行
- ldap - 为什么 Apacheds 不导入在 ldif 文件中设置了 top 属性的用户?
- r - R,参数意味着不同的行数
- database - 为什么 tableName 的 liquibase 引用停止工作?
- c# - 在 C# 中将文件另存为 .ps1
- c# - 在 ASP.NET Core MVC 中修改用户数据
- clickonce - 如何在多个环境中更改 ClickOnce 的桌面图标
- ios - 应用程序进入后台时如何停止 AirPlay 媒体暂停
- c - 如何在 Visual Studio 2019 中对 C 语言进行语法检查和格式化代码?
- html - 在 gmail 中显示的锚标签