JAXB解析xml时忽略命名空间的方法

本文转自:http://blog.csdn.net/cyzero/article/details/8423578

public static ConnectivityDeliveryResponse unmarshall(String response) throws JAXBException, ParserConfigurationException, SAXException {
         if(txLogger.isDebugEnabled()) {
             txLogger.debug(response);
         }
         JAXBContext jaxbContext = JAXBContext.newInstance(CONNECTIVITY_PACKAGE);
         Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
         StringReader reader = new StringReader(response);
         SAXParserFactory sax = SAXParserFactory.newInstance();
         sax.setNamespaceAware(false);
         XMLReader xmlReader = sax.newSAXParser().getXMLReader();
         Source source = new SAXSource(xmlReader, new InputSource(reader));
        
         ConnectivityDeliveryResponse reponse = (ConnectivityDeliveryResponse)unmarshaller.unmarshal(source);

         return reponse ;
     }

 

你可能感兴趣的:(xml,JAXB,namespace,解析异常,忽略命名空间)