2013-07-22 2 views
1

XML을 사용하여 특별히 유효성을 검사하는 데 새로운 기능이있어서 PDF를 생성하기 위해 adobe 서버를 호출하기 전에 XML의 유효성을 검사하라는 메시지가 표시되었습니다. XML을 호출합니다. 어떤 몸이 모든 요소가있는 경우 나 XML을 검증하기 위해 단계별로 도움이 될 수 있습니다하면 검증이 marshal 동안 수행해야하는 MarshallerSchema의 인스턴스를 설정할 수 있습니다XML null/empty 유효성 검사

public class MyJAXBUtil { 

    public static String obj2Xml(Class<?> class, Object object) throws ServiceException { 
     try { 
      JAXBContext jaxbContext = JAXBContext.newInstance(class); 
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); 
      StringWriter writer = new StringWriter(); 
      jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 
      jaxbMarshaller.marshal(object, writer); 
      return writer.getBuffer().toString(); 
     } catch (JAXBException jaxbException) { 
      throw new ServiceException(jaxbException); 
     } 
    } 

답변