2013-10-21 4 views
1

javax.xml.bind.MarshalException - 링크 제외 : [javax.xml.stream.XMLStreamException은 : 출력하지 XML 선언, 다른 출력이 이미 완료되었습니다 수 후.] 닷컴에서 com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal에서 .sun.xml.bind.v2.runtime.MarshallerImpl.write (MarshallerImpl.java:330) (MarshallerImpl.java:178) 여기서JAXB 출력 문제 : 이상한 예외

내 코드는 다음과 같습니다.

OutputStream output = new ByteArrayOutputStream(); 
      XMLOutputFactory xof = XMLOutputFactory.newInstance(); 
      XMLStreamWriter xsw = xof.createXMLStreamWriter(output); 


      QName root = new QName("return"); 
      JAXBElement<Customer> je = new JAXBElement<Customer>(root, Customer.class, customer); 

      xsw.writeStartDocument(); 
      xsw.setDefaultNamespace("S"); 
      xsw.writeStartElement("S", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); 
     xsw.writeStartElement("S", "Body", "http://schemas.xmlsoap.org/soap/envelope/"); 
     xsw.writeStartElement("ns0", "findCustomerResponse", "http://service.jaxws.blog/"); 

      context = JAXBContext.newInstance(Customer.class); 
      Marshaller marshaller = context.createMarshaller(); 
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 
      marshaller.marshal(je, xsw); 
      xsw.writeEndDocument(); 
      xsw.close(); 
      if(output != null) 
      return output.toString(); 

이유가 무엇입니까? 미리 감사드립니다.

답변