有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在解组时在JAXB的ValidationEventHandler中获取节点值?

当解组时发生异常时,如何在JAXB中的ValidationEventHandler中获取节点详细信息

My code:

    JAXBContext jaxbContext = JAXBContext.newInstance("com.piyush");
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = factory.newSchema(new StreamSource(new File("D:/liferay-develop/workspace/cat_test/v1/STD_MP.xsd")));
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    jaxbUnmarshaller.setSchema(schema);
    ValidationEventCollector validationCollector= new ValidationEventCollector();
    jaxbUnmarshaller.setEventHandler( validationCollector );
    STDMP ts = (STDMP)jaxbUnmarshaller.unmarshal(xml_gkuzu);
    if(validationCollector.hasEvents())
    {
        for(ValidationEvent event:validationCollector.getEvents())
        {
            String msg = event.getMessage();
            System.out.println(msg);
            // How to get the node details here ? I'm getting null value for node.
        }

共 (0) 个答案